BAT TO VBS
Hi allI run this script to remove users temp files, %temp%, perftech files,Recent,and this codeRunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351to remove internettemporary files,Cookies, History, Form data, Passwords that sotre on ie7.del /q C:\Windows\Temp\*.*cd "C:\Documents and Settings\%username%\Local Settings\Temp"DEL /F /S /Q *.*cd "C:\Documents and Settings\%username%\Recent"del /q *.*del /q C:\Windows\Prefetch\*.*RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351my question is how can i "convert" this script to VBS?!
October 19th, 2008 12:16am
We can convert a BAT file to EXE file if you would like to:http://renegadetech.blogspot.com/2006/07/how-to-convert-bat-file-or-vbs-file.htmlThe following script may also be helpful. How Can I Delete the Files in the Temporary Internet Files Folder?http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1102.mspxFor more useful script, please refer to the following webpage. http://www.microsoft.com/technet/scriptcenter/resources/qanda/hsgarch.mspx
Free Windows Admin Tool Kit Click here and download it now
October 20th, 2008 6:53am
MA_7ABK said:my question is how can i "convert" this script to VBS?!
I've created this script based on your batch file:
1
OnErrorResumeNext
2
strComputer="."
3
4
SetobjWMIService=GetObject("winmgmts:\\"&strComputer&"\root\cimv2")
5
SetobjNetwork=WScript.CreateObject("WScript.Network")
6
strCurrentUserName=objNetwork.UserName
7
8
arrFolders=Array("C:\Windows\Temp",_
9
"C:\DocumentsandSettings\"&strCurrentUserName&"\LocalSettings\Temp",_
10
"C:\DocumentsandSettings\"&strCurrentUserName&"\Recent",_
11
"C:\Windows\Prefetch")
12
13
Fori=LBound(arrFolders)toUbound(arrFolders)Step1
14
DeleteFiles(arrFolders(i))
15
Next
16
17
strCommand="RunDll32.exeInetCpl.cpl,ClearMyTracksByProcess4351"
18
SetWshShell=WScript.CreateObject("WScript.Shell")
19
WshShell.RunstrCommand,0,true
20
21
SubDeleteFiles(sFolder)
22
SetcolFileList=objWMIService.ExecQuery_
23
("ASSOCIATORSOF{Win32_Directory.Name='"&sFolder&"'""}Where"_
24
&"ResultClass=CIM_DataFile")
25
ForEachobjFileIncolFileList
26
objFile.Delete
27
Next
28
EndSub
Please test and feedback.Regards,Salvador Manaois III MCSE MCSA CEH MCITP | Enterprise/Server Admin Bytes & Badz : http://badzmanaois.blogspot.com
October 20th, 2008 9:18am
Thank you very muchSalvador Manaois IIIit dos'nt work so probably. i need it to remove all files/folder under temp, %temp%, prefetch, recnt all types files and folders.
Free Windows Admin Tool Kit Click here and download it now
October 20th, 2008 10:20pm
MA_7ABK said:
Thank you very muchSalvador Manaois IIIit dos'nt work so probably. i need it to remove all files/folder under temp, %temp%, prefetch, recnt all types files and folders.
For your reference, the following code will remove file in Temporary Internet Files Folder, My Recent Documents folder, Internet Explorer History Folder and cookies. Please note, its not a good idea to remove Prefetch folder.
http://www.edbott.com/weblog/archives/000743.html
'StepstoremoveTemporaryInternetFilesFolder
ConstTEMPORARY_INTERNET_FILES=&H20&
SetobjShell=CreateObject("Shell.Application")
SetobjFolder=objShell.Namespace(TEMPORARY_INTERNET_FILES)
SetobjFolderobjFolderItem=objFolder.Self
strPath=objFolderItem.Path&"\*.*"
SetobjFSO=CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strPath)
'StepstoremoveMyRecentDocumentsfolder
ConstMY_RECENT_DOCUMENTS=&H8&
SetobjShell=CreateObject("Shell.Application")
SetobjFolder=objShell.Namespace(MY_RECENT_DOCUMENTS)
SetobjFolderobjFolderItem=objFolder.Self
strPath=objFolderItem.Path&"\*.*"
SetobjFSO=CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strPath)
'StepstoremoveInternetExplorerHistoryFolder
ConstLOCAL_SETTINGS_HISTORY=&H22&
SetobjShell=CreateObject("Shell.Application")
SetobjFolder=objShell.Namespace(LOCAL_SETTINGS_HISTORY)
SetobjFolderobjFolderItem=objFolder.Self
strPath=objFolderItem.Path&"\*.*"
SetobjFSO=CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strPath)
'StepstoremovecookiesFolder
ConstCOOKIES=&H21&
SetobjShell=CreateObject("Shell.Application")
SetobjFolder=objShell.Namespace(COOKIES)
SetobjFolderobjFolderItem=objFolder.Self
strPath=objFolderItem.Path&"\*.*"
SetobjFSO=CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strPath)
Save the above code to vbs file.
FYI.How Can I Delete the Files in the Temporary Internet Files Folder?http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1102.mspxWe can delete more files
Incidentally, we had a premonition that as soon as we posted this column people would start asking us, Say, how do I connect to the My Pictures folder? or Is there any way to connect to the My Recent Documents folder? Because of that, we went ahead added 38 new scripts to the Script Center Script Repository, scripts that will show you how to connect to each of the special folders reachable using the Shell object. Enjoy!
October 21st, 2008 6:23am
MA_7ABK said:
Thank you very muchSalvador Manaois IIIit dos'nt work so probably. i need it to remove all files/folder under temp, %temp%, prefetch, recnt all types files and folders.Hi,Which part doesn't work? Maybe you can describe what error you are getting when running the script. You can add into the array arrFolders the other folders you want to delete the files from.Regards,Salvador Manaois III MCSE MCSA CEH MCITP | Enterprise/Server Admin Bytes & Badz : http://badzmanaois.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
October 21st, 2008 8:45am
Salvador Manaois IIII'm notgetting an error. but it's dosent remove the files/folders :S.
October 21st, 2008 10:16am
Try removing or commenting the first line ("on error resume next") and verify if you find any errors. Post the error message should you encounter one.Regards,Salvador Manaois IIIMCSE MCSA CEH MCITP | Enterprise/Server AdminBytes & Badz : http://badzmanaois.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
October 21st, 2008 10:21am
http://img73.imageshack.us/my.php?image=errorvs3.jpg
strComputer="."
SetobjWMIService=GetObject("winmgmts:\\"&strComputer&"\root\cimv2")
SetobjNetwork=WScript.CreateObject("WScript.Network")
strCurrentUserName=objNetwork.UserName
arrFolders=Array("C:\Windows\Temp",_
"C:\DocumentsandSettings\"&strCurrentUserName&"\LocalSettings\Temp",_
"C:\DocumentsandSettings\"&strCurrentUserName&"\Recent",_
"C:\Windows\Prefetch")
Fori=LBound(arrFolders)toUbound(arrFolders)Step1
DeleteFiles(arrFolders(i))
Next
strCommand="RunDll32.exeInetCpl.cpl,ClearMyTracksByProcess4351"
SetWshShell=WScript.CreateObject("WScript.Shell")
WshShell.RunstrCommand,0,true
SubDeleteFiles(sFolder)
SetcolFileList=objWMIService.ExecQuery_
("ASSOCIATORSOF{Win32_Directory.Name='"&sFolder&"'""}Where"_
&"ResultClass=CIM_DataFile")
ForEachobjFileIncolFileList
objFile.Delete
Next
EndSub
October 21st, 2008 2:41pm
The value returned is null. This means the folder (sFolder) passed to the sub procedure DeleteFiles(sFolder) is empty. Another possible cause of error (if the "on error resume next" is removed) are open files or files which you don't have the requisite permissions on.
Regards,
Salvador Manaois III MCSE MCSA CEH MCITP | Enterprise/Server Admin Bytes & Badz : http://badzmanaois.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
October 22nd, 2008 4:35am
No!!I think there is a problem with this line
ForEachobjFileIncolFileList
objFile.Delete
October 22nd, 2008 1:11pm
Hi,
I would like to explain that this is a forum for Windows Server administering topics, if you have any difficulties when customizing the scripts. I suggest that you create a new post in the MSDN forum to get further support there.
For your convenience, I have list the link as followed.
MSDN Forum
http://forums.microsoft.com/MSDN/default.aspx?SiteID=1
Thanks
Mervyn
Free Windows Admin Tool Kit Click here and download it now
October 24th, 2008 12:58pm
MA_7ABK said:
No!!I think there is a problem with this line
ForEachobjFileIncolFileList
objFile.Delete Try echoing each object's name within the collection to check if the collection is empty or not. Alternatively, you can do a check with in the For-Each loop this way:
1
ForEachobjFileIncolFileList
2
IfLen(objFile.FileName)>0Then
3
objFile.Delete
4
EndIf
5
NextRegards,Salvador Manaois III MCSE MCSA CEH MCITP | Enterprise/Server Admin Bytes & Badz : http://badzmanaois.blogspot.com
October 26th, 2008 5:09pm