-
Notifications
You must be signed in to change notification settings - Fork 0
/
CleanDisk.vbs
96 lines (86 loc) · 2.98 KB
/
CleanDisk.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
SET fso = createobject("Scripting.FilesystemObject")
Set WshShell = CreateObject("WScript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Osname = objOperatingSystem.Caption
Next
If InStr(Osname, "Windows XP") <> 0 Then
profpath = "\Local Settings\Temp"
recyclerpath = "\recycler\"
cookiespath = "%USERPROFILE%\Cookies"
else
profpath = "\AppData\Local\Temp"
recyclerPath = "\$recycle.bin\"
cookiespath = "%APPDATA%\Microsoft\Windows\Cookies"
End if
'For cleaning Appdata for every user profile
Set objRegistry=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
For Each objSubkey In arrSubkeys
strValueName = "ProfileImagePath"
strSubPath = strKeyPath & "\" & objSubkey
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
set fld = fso.GetFolder(strValue)
if fso.FolderExists( strValue & profpath) then
set objTempFolder = fso.GetFolder(strValue & profpath)
If InStr(objTempFolder.Path, "systemprofile") = 0 And InStr(objTempFolder.Path, "LocalService") = 0 And InStr(objTempFolder.Path, "NetworkService") = 0 Then
For Each oFile In objTempFolder.files
fso.DeleteFile oFile
Next
For Each oSubFolder In objTempFolder.SubFolders
Call KillSubFolders (oSubFolder)
Next
End If
End if
Next
'For cleaning Windows Temp folder
Set oFolder = fso.GetFolder(WshShell.ExpandEnvironmentStrings("%TEMP%"))
For Each oFile In oFolder.files
fso.DeleteFile oFile
Next
For Each oSubFolder In oFolder.SubFolders
Call KillSubFolders (oSubFolder)
Next
'For cleaning Windows prefetch folder
Set oFolder = fso.GetFolder(WshShell.ExpandEnvironmentStrings("%systemroot%\prefetch"))
For Each oFile In oFolder.files
fso.DeleteFile oFile
Next
For Each oSubFolder In oFolder.SubFolders
Call KillSubFolders (oSubFolder)
Next
'For cleaning cookies folder
Set oFolder = fso.GetFolder(WshShell.ExpandEnvironmentStrings(cookiespath))
For Each oFile In oFolder.files
fso.DeleteFile oFile
Next
For Each oSubFolder In oFolder.SubFolders
Call KillSubFolders (oSubFolder)
Next
'For cleaning Recycle Bin
Set objSWbemServices = GetObject _
("WinMgmts:Root\Cimv2")
Set colDisks = objSWbemServices.ExecQuery _
("Select * From Win32_LogicalDisk " & _
"Where DriveType = 3")
For Each objDisk In colDisks
folderpath = objDisk.DeviceId&recyclerpath
For Each oFile In oFolder.files
fso.DeleteFile oFile
Next
Set oFolder = fso.GetFolder(folderpath)
For Each oSubFolder In oFolder.SubFolders
Call KillSubFolders (oSubFolder)
Next
Next
'Wscript.echo Err.number
Sub KillSubFolders (SubPath)
fso.DeleteFolder SubPath
End Sub