#1 02 Jun 2010 22:20

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 997
Website

Roaming profiles - speedup slow logon and logoff times.

Heres a new script for clearing down Roaming User Profile folders.
Rather than clearing out everything, this script deletes selected files based on their last modified date.

http://ss64.com/vb/syntax-profile.html

I'm sure theres 1001 ways of tackling this issue, be interested to hear how others approach it (and which folders you clear down).

Offline

#2 07 Jun 2010 18:23

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 997
Website

Re: Roaming profiles - speedup slow logon and logoff times.

A minor update: for compatibility with Windows 7 the script now uses the AppData variable rather than hard coding "Application Data"

Option Explicit

'Variables
Dim objShell,FSO,dtmStart,dtmEnd
Dim strUserProfile,strAppData,objFile
Dim objCache1,objCache2,objCache3,objCache4,objCache5,objCache6,objCache7

Wscript.echo "Profile cleanup starting"
dtmStart = Timer()

' Get the current users profile folder
Set objShell = CreateObject("WScript.Shell")
strUserProfile=objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strAppData=objShell.ExpandEnvironmentStrings("%APPDATA%")
'Wscript.echo strAppData

' Set reference to the file system
Set FSO = createobject("Scripting.FileSystemObject")

' Set variables for each folder that will be cleared down

Set objCache1 = FSO.GetFolder(strUserProfile & "\Cookies")
Set objCache2 = FSO.GetFolder(strUserProfile & "\Recent")
Set objCache3 = FSO.GetFolder(strAppData & "\Microsoft\Office\Recent")
Set objCache4 = FSO.GetFolder(strAppData & "\Microsoft\CryptnetUrlCache\Content")
Set objCache5 = FSO.GetFolder(strAppData & "\Sun\Java\Deployment\cache")
Set objCache6 = FSO.GetFolder(strAppData & "\Macromedia\Flash Player")
Set objCache7 = FSO.GetFolder(strUserProfile & "\Oracle Jar Cache")

' Call the DeleteOlder subroutine for each

DeleteOlder objCache1,90 'Days to keep cookies
DeleteOlder objCache2,14 'Days to keep recent files
DeleteOlder objCache3,14 'Days to keep recent MS Office files
DeleteOlder objCache4,5  'Days to keep CryptnetUrlCache
DeleteOlder objCache5,5  'Days to keep Java cache
DeleteOlder objCache6,3  'Days to keep flash data
DeleteOlder objCache7,14 'Days to keep Oracle Jar Cache

' Print completed message

dtmEnd = Timer()
Wscript.echo "Profile cleanup complete, elapsed time: " & FormatNumber(dtmEnd-dtmStart,2) & " seconds"
Set FSO = Nothing

' Subroutines below

Sub DeleteOlder(objFolder, intDays)
' Delete all files in objFolder older than intDays
For each objFile in objFolder.files
   If DateDiff("d", objFile.DateLastModified,Now) > intDays Then
      'Wscript.echo "File: " & objFile.Name
      objFile.Delete(True)
   End If
Next
Set objFile = Nothing
End Sub

Offline

#3 10 Aug 2010 15:27

Leeroy
Member
Registered: 10 Aug 2010
Posts: 1

Re: Roaming profiles - speedup slow logon and logoff times.

Hi,

I'm using your script to clean up our users profile but it doesnt seem to check subfolders.  Is there a way of doing this?  Specifically the subfolders within "strUserProfile & "\Local Settings\Temporary Internet Files"

Offline

#4 10 Aug 2010 18:40

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 997
Website

Re: Roaming profiles - speedup slow logon and logoff times.

You could modify the script to cope with subfolders but I advise against it, it's better to be specific about what is being deleted.

Firstly "subfolders within strUserProfile" - you have to be careful about randomly deleting just anything from the user profile. If you delete the entire profile including NTuser.dat then windows will rebuild everything based on the default user settings, but if you delete some files and not others, then strange things can happen, the main area that tends to be problematic is the 'Local Settings' folder - it's too easy to cause a situation where an application will try to save some data to its log file (which is now NULL) and will then crash or throw a cryptic error or just refuse to launch at all. By targetting specific folders you can test and be sure no bad things like that are going to happen.

"Temporary Internet Files" - these are a bit of a special case, they involve registry settings as well as files, the best way to control them is via group policy:
Limit the IE cache size via Group policy
http://www.petri.co.il/controlling_ie_c … ia_gpo.htm

If you still need to reduce the profile size further, some other things to consider are 'Mandatory Profiles' and/or using 'Folder Redirection' to put, for example the Desktop folder, on a network drive.

Offline

#5 03 Feb 2011 21:54

DaddyMonkeyMan
Member
Registered: 03 Feb 2011
Posts: 1

Re: Roaming profiles - speedup slow logon and logoff times.

Simon,

This script is excellent! Thanks! The only issue I ran across was that the script would error if the destination folder did not exist in the user's profile. For example, if the users profile did not contain an "Oracle Jar Cache" the script would exit with an error. I modified the script to account for this behavior. I am sure there are more elegant ways of handling the issue, but this worked for me:

Option Explicit

'Variables
Dim objShell,FSO,dtmStart,dtmEnd
Dim strUserProfile,strAppData,objFile
Dim objCache

Wscript.echo "Profile cleanup starting"
dtmStart = Timer()

' Get the current users profile folder
Set objShell = CreateObject("WScript.Shell")
strUserProfile=objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strAppData=objShell.ExpandEnvironmentStrings("%APPDATA%")
'Wscript.echo strAppData

' Set reference to the file system
Set FSO = createobject("Scripting.FileSystemObject")

' Check if each folder exists. If so, call the "DeleteOlder" subroutine and clear
' items older than the specified age

If FSO.FolderExists(strUserProfile & "\Cookies") = True Then
    Set objCache = FSO.GetFolder(strUserProfile & "\Cookies")
    DeleteOlder objCache,90 'Days to keep cookies
End If
If FSO.FolderExists(strUserProfile & "\Recent") = True Then
    Set objCache = FSO.GetFolder(strUserProfile & "\Recent")
    DeleteOlder objCache,14 'Days to keep recent files
End If
If FSO.FolderExists(strAppData & "\Microsoft\Office\Recent") = True Then
    Set objCache = FSO.GetFolder(strAppData & "\Microsoft\Office\Recent")
    DeleteOlder objCache,14 'Days to keep recent MS Office files
End If
If FSO.FolderExists(strAppData & "\Microsoft\CryptnetUrlCache\Content") = True Then
    Set objCache = FSO.GetFolder(strAppData & "\Microsoft\CryptnetUrlCache\Content")
    DeleteOlder objCache,5 'Days to keep CryptnetUrlCache
End If
If FSO.FolderExists(strAppData & "\Microsoft\CryptnetUrlCache\MetaData") = True Then
    Set objCache = FSO.GetFolder(strAppData & "\Microsoft\CryptnetUrlCache\MetaData")
    DeleteOlder objCache,5 'Days to keep CryptnetUrlMetaData
End If
If FSO.FolderExists(strAppData & "\Sun\Java\Deployment\cache") = True Then
    Set objCache = FSO.GetFolder(strAppData & "\Sun\Java\Deployment\cache")
    DeleteOlder objCache,5  'Days to keep Java cache
End If
If FSO.FolderExists(strAppData & "\Macromedia\Flash Player") = True Then
    Set objCache = FSO.GetFolder(strAppData & "\Macromedia\Flash Player")
    DeleteOlder objCache,3  'Days to keep flash data
End If
If FSO.FolderExists(strUserProfile & "\Oracle Jar Cache") = True Then
    Set objCache = FSO.GetFolder(strUserProfile & "\Oracle Jar Cache")
    DeleteOlder objCache,14 'Days to keep Oracle Jar Cache
End If


' Print completed message

dtmEnd = Timer()
Wscript.echo "Profile cleanup complete, elapsed time: " & FormatNumber(dtmEnd-dtmStart,2) & " seconds"
Set FSO = Nothing

' Subroutines below

Sub DeleteOlder(objFolder, intDays)
' Delete all files in objFolder older than intDays
For each objFile in objFolder.files
   If DateDiff("d", objFile.DateLastModified,Now) > intDays Then
      'Wscript.echo "File: " & objFile.Name
      objFile.Delete(True)
   End If
Next
Set objFile = Nothing
End Sub

You might note that I also included the CryptNetURLCache\MetaData folder in this version...it doesn't take up much room, but I assume the metadata is worthless without the content! :-)

Thanks for this! It should prove to be a big problem solver for us!

Offline

#6 04 Feb 2011 13:25

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 997
Website

Re: Roaming profiles - speedup slow logon and logoff times.

Yes those checks are a very worthwhile addition, I was assuming the profile sub folders would all be standardised but thats not always true.

I'm pretty sure all those If() statements can be wrapped into the main delete loop, will look at this more when I get time over the weekend.

Thanks

Offline

#7 17 Feb 2011 21:10

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 997
Website

Re: Roaming profiles - speedup slow logon and logoff times.

Heres an improved version that checks if each folder exists:

Option Explicit

'Variables
Dim objShell,FSO,dtmStart,dtmEnd
Dim strUserProfile,strAppData
Dim objFile,objFolder,objCache

Wscript.echo "Profile cleanup starting"
dtmStart = Timer()

' Get the current users Profile and ApplicationData folders
Set objShell = CreateObject("WScript.Shell")
strUserProfile=objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strAppData=objShell.ExpandEnvironmentStrings("%APPDATA%")
'Wscript.echo strAppData

' Set reference to the file system
Set FSO = createobject("Scripting.FileSystemObject")

' Call the DeleteOlder subroutine for each folder

DeleteOlder 90, strUserProfile & "\Cookies"  'Days to keep cookies
DeleteOlder 14, strUserProfile & "\Recent"   'Days to keep recent files
DeleteOlder 14, strAppData & "\Microsoft\Office\Recent" 'Days to keep recent MS Office files
DeleteOlder 5, strAppData & "\Microsoft\CryptnetUrlCache\Content"  'IE certificate cache
DeleteOlder 5, strAppData & "\Microsoft\CryptnetUrlCache\MetaData" 'IE cert info
DeleteOlder 5, strAppData & "\Sun\Java\Deployment\cache" 'Days to keep Java cache
DeleteOlder 3, strAppData & "\Macromedia\Flash Player"   'Days to keep flash data
DeleteOlder 14, strUserProfile & "\Oracle Jar Cache"    'Days to keep Oracle Jar Cache

' Print completed message

dtmEnd = Timer()
Wscript.echo "Profile cleanup complete, elapsed time: " & FormatNumber(dtmEnd-dtmStart,2) & " seconds"
Set FSO = Nothing

' Subroutines below

Sub DeleteOlder(intDays,strPath)
' Delete files from strPath that are more than intDays old
If FSO.FolderExists(strPath) = True Then
   Set objFolder = FSO.GetFolder(strPath)
   For each objFile in objFolder.files
      If DateDiff("d", objFile.DateLastModified,Now) > intDays Then
         'Wscript.echo "File: " & objFile.Name
         objFile.Delete(True)
      End If
   Next
   Set objFile = Nothing
   Set objCache = Nothing
End If
End Sub

http://ss64.com/vb/syntax-profile.html

Offline

#8 27 Jul 2011 16:15

ptcruisergt
Member
Registered: 27 Jul 2011
Posts: 1

Re: Roaming profiles - speedup slow logon and logoff times.

Thank you for this script.  It resolved a problem with an unwieldly amount of cookies in our user profiles.  One problem remains, however.  Flash Player cookies sad

How would you handle Flash Player cookies with this script?  They are stored in individual folders in the macromedia.com and #SharedObjects folders in %appdata%\Macromedia\Flash Player\.

Last edited by ptcruisergt (27 Jul 2011 16:16)

Offline

#9 23 Aug 2011 20:04

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 997
Website

Re: Roaming profiles - speedup slow logon and logoff times.

^ because Flash cookies are in multiple sub folders I think you will need to take a slightly different approach.

With Adobe Flash Player 10.3 and above, clearing browser cookies in IE 8, 9, Firefox or Chrome will automatically clear the Flash cookies as well.
http://blogs.msdn.com/b/ie/archive/2011 … asier.aspx

So setting a group policy for "Delete browsing history on exit" (with the relevant options for what you want to clear) is all you need as long as your Flash Player is up-to-date.

Offline

#10 05 Sep 2011 05:03

ruukuxp
Member
Registered: 05 Sep 2011
Posts: 2

Re: Roaming profiles - speedup slow logon and logoff times.

Hi all, this is a pretty great script.  I've customized it so it will only clean out Recent/Cookies/Office Recent folders, but when I run this script as a non-admin on Win7 PC, I get a Permission denied on the "For each objFile in objFolder.files" line in of the DeleteOlder sub-routine.  I'm still rather new to VBS, can someone help?

EDIT: Never mind I just figured it out.  Although in Win7, there is a Cookies folder under the root of the user profile, it is actually a pointer to the strAppData\Microsoft\Windows\Cookies folder, and I guess VB isn't able to access that pointer the same way when user is not admin.  Same goes for the Recent folder.  I'll just need to implement OS detection and then set different variables as needed.

Last edited by ruukuxp (05 Sep 2011 05:13)

Offline

#11 05 Sep 2011 12:37

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 997
Website

Re: Roaming profiles - speedup slow logon and logoff times.

An alternative to OS detection would be reading the Cookies folder location from the registry, you can read how to do that here

For /f "tokens=3*" %%G in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Cookies" ^| Find "REG_"') do set _Cookies=%%H

Offline

#12 06 Sep 2011 03:55

ruukuxp
Member
Registered: 05 Sep 2011
Posts: 2

Re: Roaming profiles - speedup slow logon and logoff times.

The link to the User Shell Folders is great!  Unfortunately non-admins can't run reg query in our Win7 PCs... Since our support very limited number of workstation OS, I can just specify paths per OS.  Already tested to be working well for us.  Thanks again.

Offline

#13 19 Dec 2012 21:12

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 997
Website

Re: Roaming profiles - speedup slow logon and logoff times.

Now updated to include OS detection

http://ss64.com/vb/syntax-profile.html

Offline

Board footer

Powered by FluxBB