![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Autorun Script to empty folders Hello everyone, I need a script to empty some folders at system startup, nothing very complicated. But, from the sample code below, I need it to use the environment variables to get the %userprofile% temp folder, %windir% temp folder, and maybe, if you think it is a good thing to do, clean printers spool folder too (system32\spool\printers\*.*). On Error Resume Next Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.DeleteFile("C:\Documents and Settings\owner\Configurações locais\Temp\*.*"), 1 objFSO.DeleteFolder("C:\Documents and Settings\owner\Configurações locais\Temp\*.*"), 1 objFSO.DeleteFile("C:\WINDOWS\Temp\*.*"), 1 objFSO.DeleteFolder("C:\WINDOWS\Temp\*.*"), 1 As always, any help would be appreciated. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Autorun Script to empty folders "Tyler Durden" <abuse@xxxxxx> wrote in message news:OEeUUbRDJHA.1224@xxxxxx Quote: > Hello everyone, > > I need a script to empty some folders at system startup, nothing very > complicated. But, from the sample code below, I need it to use the > environment variables to get the %userprofile% temp folder, %windir% temp > folder, and maybe, if you think it is a good thing to do, clean printers > spool folder too (system32\spool\printers\*.*). > > On Error Resume Next > Set objFSO = CreateObject("Scripting.FileSystemObject") > objFSO.DeleteFile("C:\Documents and Settings\owner\Configurações > locais\Temp\*.*"), 1 > objFSO.DeleteFolder("C:\Documents and Settings\owner\Configurações > locais\Temp\*.*"), 1 > objFSO.DeleteFile("C:\WINDOWS\Temp\*.*"), 1 > objFSO.DeleteFolder("C:\WINDOWS\Temp\*.*"), 1 get these from the OS without having to make any assumptions: Set oWSH = CreateObject("WScript.Shell") With oWSH.Environment("Process") sUsrTmp = .Item("Temp") sWinTmp = .Item("WinDir") & "\Temp" End With sSpooler = oWSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT" _ & "\CurrentVersion\Print\Printers\DefaultSpoolDirectory") MsgBox "User Temp Folder:" & vbTab & vbTab & sUsrTmp & vbLf _ & "Windows Temp Folder:" & vbTab & sWinTmp & vbLf _ & "Spooler Folder:" & vbTab & vbTab & sSpooler |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Autorun Script to empty folders "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message news:euZU$ASDJHA.484@xxxxxx Quote: > "Tyler Durden" <abuse@xxxxxx> wrote in message > news:OEeUUbRDJHA.1224@xxxxxx Quote: >> Hello everyone, >> >> I need a script to empty some folders at system startup, nothing very >> complicated. But, from the sample code below, I need it to use the >> environment variables to get the %userprofile% temp folder, %windir% temp >> folder, and maybe, if you think it is a good thing to do, clean printers >> spool folder too (system32\spool\printers\*.*). >> >> On Error Resume Next >> Set objFSO = CreateObject("Scripting.FileSystemObject") >> objFSO.DeleteFile("C:\Documents and Settings\owner\Configurações >> locais\Temp\*.*"), 1 >> objFSO.DeleteFolder("C:\Documents and Settings\owner\Configurações >> locais\Temp\*.*"), 1 >> objFSO.DeleteFile("C:\WINDOWS\Temp\*.*"), 1 >> objFSO.DeleteFolder("C:\WINDOWS\Temp\*.*"), 1 > You can use the 'Environment' & 'RegRead' methods of 'WScript.Shell' to > get these from the OS without having to make any assumptions: > > Set oWSH = CreateObject("WScript.Shell") > With oWSH.Environment("Process") > sUsrTmp = .Item("Temp") > sWinTmp = .Item("WinDir") & "\Temp" > End With > sSpooler = oWSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT" _ > & "\CurrentVersion\Print\Printers\DefaultSpoolDirectory") > > MsgBox "User Temp Folder:" & vbTab & vbTab & sUsrTmp & vbLf _ > & "Windows Temp Folder:" & vbTab & sWinTmp & vbLf _ > & "Spooler Folder:" & vbTab & vbTab & sSpooler deleted might already be locked. Also, I'm not sure which user's environment will be referenced by this code at startup time, but I suspect it may not be the user of interest. I'm not sure this is a good thing to do. It would be better for all applications using TEMP folders to delete their temp files when they are finished with them. Unfortunately, temp folders are used for a lot of uses where persistence is important. /Al |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Autorun Script to empty folders Thank you James. What about the method used in my script to empty the folder? It could be done in a better way? "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message news:euZU$ASDJHA.484@xxxxxx Quote: > "Tyler Durden" <abuse@xxxxxx> wrote in message > news:OEeUUbRDJHA.1224@xxxxxx Quote: >> Hello everyone, >> >> I need a script to empty some folders at system startup, nothing very >> complicated. But, from the sample code below, I need it to use the >> environment variables to get the %userprofile% temp folder, %windir% temp >> folder, and maybe, if you think it is a good thing to do, clean printers >> spool folder too (system32\spool\printers\*.*). >> >> On Error Resume Next >> Set objFSO = CreateObject("Scripting.FileSystemObject") >> objFSO.DeleteFile("C:\Documents and Settings\owner\Configurações >> locais\Temp\*.*"), 1 >> objFSO.DeleteFolder("C:\Documents and Settings\owner\Configurações >> locais\Temp\*.*"), 1 >> objFSO.DeleteFile("C:\WINDOWS\Temp\*.*"), 1 >> objFSO.DeleteFolder("C:\WINDOWS\Temp\*.*"), 1 > You can use the 'Environment' & 'RegRead' methods of 'WScript.Shell' to > get these from the OS without having to make any assumptions: > > Set oWSH = CreateObject("WScript.Shell") > With oWSH.Environment("Process") > sUsrTmp = .Item("Temp") > sWinTmp = .Item("WinDir") & "\Temp" > End With > sSpooler = oWSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT" _ > & "\CurrentVersion\Print\Printers\DefaultSpoolDirectory") > > MsgBox "User Temp Folder:" & vbTab & vbTab & sUsrTmp & vbLf _ > & "Windows Temp Folder:" & vbTab & sWinTmp & vbLf _ > & "Spooler Folder:" & vbTab & vbTab & sSpooler > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Autorun Script to empty folders "Tyler Durden" <abuse@xxxxxx> wrote in message news:uv2fDJdDJHA.4724@xxxxxx Quote: > Thank you James. What about the method used in my script to empty the > folder? It could be done in a better way? of these directories. If the assumption is correct, the code below will likely work for you. Please consider Al's advice and test this before deploying it. I share Al's concern about the user's environment at startup time, which is why I put in a test for the length of the variable before executing the delete to make sure it does not delete from the root. The code will likely not completely clean out either of the temp directories since it cannot delete files that are in use and locked (which you would not want it to do, anyway). '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Option Explicit Dim oWSH Set oWSH = CreateObject("WScript.Shell") With oWSH.Environment("Process") EmptyDir .Item("Temp") EmptyDir .Item("WinDir") & "\Temp" End With EmptyDir oWSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT" _ & "\CurrentVersion\Print\Printers\DefaultSpoolDirectory") Sub EmptyDir(sFolderPath) Dim oFSO, oFile, oFolder Set oFSO = CreateObject("Scripting.FileSystemObject") If Len(sFolderPath) And oFSO.FolderExists(sFolderPath) Then On Error Resume Next With oFSO.GetFolder(sFolderPath) For Each oFile in .Files oFile.Delete True Next For Each oFolder in .SubFolders oFolder.Delete True Next End With End If End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Autorun Script to empty folders Thank You! "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message news:O8H9RmfDJHA.4176@xxxxxx Quote: > "Tyler Durden" <abuse@xxxxxx> wrote in message > news:uv2fDJdDJHA.4724@xxxxxx Quote: >> Thank you James. What about the method used in my script to empty the >> folder? It could be done in a better way? > I am going to assume you want to empty all files and subfolders out > each of these directories. If the assumption is correct, the code below > will likely work for you. > > Please consider Al's advice and test this before deploying it. I share > Al's concern about the user's environment at startup time, which is why I > put in a test for the length of the variable before executing the delete > to make sure it does not delete from the root. > > The code will likely not completely clean out either of the temp > directories since it cannot delete files that are in use and locked (which > you would not want it to do, anyway). > > '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Option Explicit > > Dim oWSH > > Set oWSH = CreateObject("WScript.Shell") > With oWSH.Environment("Process") > EmptyDir .Item("Temp") > EmptyDir .Item("WinDir") & "\Temp" > End With > EmptyDir oWSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT" _ > & "\CurrentVersion\Print\Printers\DefaultSpoolDirectory") > > Sub EmptyDir(sFolderPath) > Dim oFSO, oFile, oFolder > Set oFSO = CreateObject("Scripting.FileSystemObject") > If Len(sFolderPath) And oFSO.FolderExists(sFolderPath) Then > On Error Resume Next > With oFSO.GetFolder(sFolderPath) > For Each oFile in .Files > oFile.Delete True > Next > For Each oFolder in .SubFolders > oFolder.Delete True > Next > End With > End If > End Sub > '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Autorun Script to empty folders "Al Dunbar" <AlanDrub@xxxxxx> wrote in message news:OrNEe0WDJHA.3432@xxxxxx Quote: > > "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message > news:euZU$ASDJHA.484@xxxxxx Quote: >> "Tyler Durden" <abuse@xxxxxx> wrote in message >> news:OEeUUbRDJHA.1224@xxxxxx Quote: >>> Hello everyone, >>> >>> I need a script to empty some folders at system startup, nothing very >>> complicated. But, from the sample code below, I need it to use the >>> environment variables to get the %userprofile% temp folder, %windir% >>> temp folder, and maybe, if you think it is a good thing to do, clean >>> printers spool folder too (system32\spool\printers\*.*). >>> >>> On Error Resume Next >>> Set objFSO = CreateObject("Scripting.FileSystemObject") >>> objFSO.DeleteFile("C:\Documents and Settings\owner\Configurações >>> locais\Temp\*.*"), 1 >>> objFSO.DeleteFolder("C:\Documents and Settings\owner\Configurações >>> locais\Temp\*.*"), 1 >>> objFSO.DeleteFile("C:\WINDOWS\Temp\*.*"), 1 >>> objFSO.DeleteFolder("C:\WINDOWS\Temp\*.*"), 1 >> You can use the 'Environment' & 'RegRead' methods of 'WScript.Shell' >> to get these from the OS without having to make any assumptions: >> >> Set oWSH = CreateObject("WScript.Shell") >> With oWSH.Environment("Process") >> sUsrTmp = .Item("Temp") >> sWinTmp = .Item("WinDir") & "\Temp" >> End With >> sSpooler = oWSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT" _ >> & "\CurrentVersion\Print\Printers\DefaultSpoolDirectory") >> >> MsgBox "User Temp Folder:" & vbTab & vbTab & sUsrTmp & vbLf _ >> & "Windows Temp Folder:" & vbTab & sWinTmp & vbLf _ >> & "Spooler Folder:" & vbTab & vbTab & sSpooler > That might work at logon time, though some of the files and folders to be > deleted might already be locked. Also, I'm not sure which user's > environment will be referenced by this code at startup time, but I suspect > it may not be the user of interest. > > I'm not sure this is a good thing to do. It would be better for all > applications using TEMP folders to delete their temp files when they are > finished with them. Unfortunately, temp folders are used for a lot of uses > where persistence is important. My C:\Documents and Settings\Paul\Local Settings\Temp folder contains 3,763 files in 66 folders totalling 1,874,581,244 bytes. The timestamps range from Sept, 2006 (when I think I installed this WXP) to today. A huge number of files have names like DDT.m0w880v9ksn57fdm1k0yvpkfh.tmp, and large groups of these files are created at specific times on certain days. There are a lot of hidden folders, with names like Temporary Directory 2 for Scriptomatic2.zip. Adobe, Nero, and other sofware vendors also have folders here. And there are a huge number of xml files with names like IMT5D.xml. I have no idea what can and cannot be safely deleted, but I suspect most of this stuff is junk. -Paul Randall |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Autorun Script to empty folders "Paul Randall" <paulr90@xxxxxx> wrote in message news:eC5roPhDJHA.524@xxxxxx Quote: > > "Al Dunbar" <AlanDrub@xxxxxx> wrote in message > news:OrNEe0WDJHA.3432@xxxxxx Quote: >> That might work at logon time, though some of the files and folders to be >> deleted might already be locked. Also, I'm not sure which user's >> environment will be referenced by this code at startup time, but I >> suspect it may not be the user of interest. >> >> I'm not sure this is a good thing to do. It would be better for all >> applications using TEMP folders to delete their temp files when they are >> finished with them. Unfortunately, temp folders are used for a lot of >> uses where persistence is important. > I agree. > My C:\Documents and Settings\Paul\Local Settings\Temp folder contains > 3,763 files in 66 folders totalling 1,874,581,244 bytes. The timestamps > range from Sept, 2006 (when I think I installed this WXP) to today. A > huge number of files have names like DDT.m0w880v9ksn57fdm1k0yvpkfh.tmp, > and large groups of these files are created at specific times on certain > days. There are a lot of hidden folders, with names like Temporary > Directory 2 for Scriptomatic2.zip. Adobe, Nero, and other sofware vendors > also have folders here. And there are a huge number of xml files with > names like IMT5D.xml. I have no idea what can and cannot be safely > deleted, but I suspect most of this stuff is junk. like with 'rd /s /q "%temp%"' (verifying %temp% is set first, of course) and have yet to have it cause a problem. The directory itself is never actually deleted since it contains in-use files. It may one day burn me, but temp is supposed to be temp and should never contain persistent files. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Autorun script for XP & Vista | VB Script | |||
| Empty Folders Automatically | Vista mail | |||
| file folder icons display non-empty folders as empty | Vista file management | |||
| All Folders Empty | Vista mail | |||
| empty folders??? | Vista networking & sharing | |||