+ Post New Thread
Results 1 to 1 of 1
Scripts Thread, Saving temp files from a mandatory profile in Coding and Web Development; As requested by Danp, here is the solution for my problem.... Issue: Students are on a mandatory profile in a ...
  1. #1

    Join Date
    May 2013
    Thank Post
    Thanked 4 Times in 3 Posts
    Rep Power

    Saving temp files from a mandatory profile

    As requested by Danp, here is the solution for my problem....

    Issue: Students are on a mandatory profile in a windows 7 environment, this means they have no local user profile on the PCs. If they open a file from web mail (using IE as it's the only thing available), they invariable enable editing, then work on the file without saving it to thier file storage location!! When they save later on they tend not to do 'save as' (and believe me we have told them lots to do that). By default IE stores any document in the IE temp folder on the profile.
    If you don't have a profile on the PC then the files are deleted when you log off......cue wailing students "I worked for hours on it and now it's lost!!!"

    Solution: I have enable a log off script in GPO to run a .vbs, this in turn calls a powershell script to save the files. Seems complicated - yes but it works and if you set the powershell script to run at log off it run as the student, who don't have execution rights.The VB script also waits until the powershell code has completed before it ends, this makes sure that the files have been copied over.

    VB code

    on error resume next
    const overwriteExisting = true
    const forceRemoval=true
    const forceDelete=true
    const updateProfile=true
    set objshell=wscript.createobject("wscript.shell")
    set objnet=wscript.createobject("wscript.network")
    Set objFSO=wscript.createObject("Scripting.FileSystemObject")
    '------run copy-----------------------------------
    objShell.run("powershell -executionpolicy bypass -noexit -file \\yourfilelocationhere\netlogon\filesavetemp.ps1")
     WaitForIdle ".", "powershell", "3"  
     Sub WaitForIdle(strComputer, strProcessName, intIdleSec)  
     Dim bolIdle : bolIdle = False  
     Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")  
     Dim strObjKeyPath : strObjKeyPath = "Win32_PerfRawData_PerfProc_Process.Name='" & strProcessName & "'"  
     Dim objPerfInstance : Set objPerfInstance = objWMIService.get(strObjKeyPath)  
     Dim intPercProcTime1 : intPercProcTime1 = objPerfInstance.PercentProcessorTime  
     Dim intProcTimeStamp1 : intProcTimeStamp1 = objPerfInstance.TimeStamp_Sys100NS  
     Dim intElemCount : intElemCount = CInt(intIdleSec) - 1  
     ReDim arrProcPercents(intElemCount)  
     Dim i : i = 0  
     Dim PercentProcessorTime, arrTemp, intPercProcTime2, intProcTimeStamp2  
     Do While Not bolIdle  
         WScript.Sleep 1000  
         Set objPerfInstance = objWMIService.get(strObjKeyPath)  
         intPercProcTime2 = objPerfInstance.PercentProcessorTime  
         intProcTimeStamp2 = objPerfInstance.TimeStamp_Sys100NS  
         If (intProcTimeStamp2 - intProcTimeStamp1) = 0 Then  
             WScript.Echo "Error, probably " & strProcessName & " not found running"  
             Exit Do  
         PercentProcessorTime = ((intPercProcTime2 - intPercProcTime1) _  
                                                    / (intProcTimeStamp2 - intProcTimeStamp1))  
     '                 WScript.Echo FormatPercent(PercentProcessorTime)  
              ' add value to array  
             arrProcPercents(i) = FormatPercent(PercentProcessorTime)  
             ' if the number of seconds have been met then check the array  
         If i = (intElemCount) Then  
             ' look at the array and filter for values of 0.00%  
             arrTemp = Filter(arrProcPercents, "0.00%")  
                  ' if the array size of the filtered and the original is the same then  
                  ' all the values for the time specified where 0.00%  
             If UBound(arrTemp) = intElemCount Then  
                 ' set bolIdle = True to exit the Do...Loop  
                 bolIdle = True  
             End If  
             ' if all the values where not 0.00% then reset the counter and   
             ' array index to update  
                 i = 0  
             ' increment the counter/array index  
                 i = i + 1  
             End If  
         End If      
         intPercProcTime1 = intPercProcTime2  
         intProcTimeStamp1 = intProcTimeStamp2  
     End Sub
    The Powershell script....this checks who the user is and then checks to see if they have a folder created yet (forward planning FTW - next years intake are automatically catered for), then it copies the temp files to the folder....but only the ones you specify, so we don't fill yp your servers with all the images and stuff from IE

    $strUser = $env:username
    $path = "\\yourfileserver\saved\$strUser"
    if(!(test-path -Path $path))
     new-item -Path $path -type directory
    get-childitem "C:\users\TEMP.COLLEGE*\AppData\local\microsoft\windows\Temporary Internet Files\content.IE5\*\*"  -include @("*.docx","*.ppt","*.xlsx","*.doc","*.csv","*.xls","*.pptx","*.pub") -force -recurse |
    where-object { (-not $_.PSIsContainer) -and ($_.LastWriteTime -lt (get-date).AddDays(+60)) } | Copy-item -Destination "\\yourfileserver\saved\$strUser" -recurse -force
    I know the code is not overly clean on either one but I was rushed slightly

  2. 2 Thanks to FeralAI:

    Danp (20th February 2014), Jowley (19th March 2014)

+ Post New Thread

Similar Threads

  1. Replies: 1
    Last Post: 22nd February 2012, 12:10 PM
  2. Replies: 1
    Last Post: 15th September 2011, 11:08 AM
  3. Preventing users saving to temp files?
    By Tegwin in forum Windows
    Replies: 2
    Last Post: 8th March 2010, 11:59 AM
  4. offline files with mandatory profile?
    By sidewinder in forum Windows
    Replies: 1
    Last Post: 2nd October 2008, 11:20 AM
  5. Saving video files from BBC new website pages.
    By tosca925 in forum How do you do....it?
    Replies: 3
    Last Post: 11th June 2007, 11:22 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts