-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSYS-WIN.PURGE.vbs
322 lines (322 loc) · 12.3 KB
/
SYS-WIN.PURGE.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
' **************************************************************************************************************:
' ********************************************* PURGE TEMP & HIS DIR *******************************************:
' **************************************************************************************************************:
' Author: JBallard (JEB) :
' Date: 2018.9.05 :
' Script: SYS-WIN.PURGE.vbs :
' Dir: \\JBALLARD-9520\C$\0_SVN\2_DEV\0_SCRIPTS.Src\0_USEFUL.Dev\3_CLEAN.Dev :
' Purpose: A VBScript that purges out all Windows TEMP, History, PREFETCH, & Cache Directories :
' Version: 1.0 :
' **************************************************************************************************************:
' **************************************************************************************************************:
'
' **************************************************:
' DEFINE PARAMS, CONFIG PATHS, IMPORT CLASSES :
' **************************************************:
DIM FileSystem
'
CONST DeleteReadOnly = TRUE
CONST DeleteFolder = TRUE
CONST DeleteFile = TRUE
'
Sub RunApplication(ByVal StrFile)
DIM WShell : SET WShell = CreateObject("WScript.Shell")
WShell.Run Chr(34) & StrFile & Chr(34), 8, FALSE
End Sub
'
SET ObjectFSO = CreateObject("Scripting.FileSystemObject")
SET ObjectLog = ObjectFSO.CreateTextFile("\\JBALLARD-9520\C$\0_SVN\7_LOGS\SYS-WIN.PURGE.jeb")
'
' **************************************************:
' FUNCTION - DELETE ALL TEMP USER & SYSTEM FILES :
' **************************************************:
SET OShell = CreateObject("WScript.Shell")
SET FileSystem = CreateObject("Scripting.FileSystemObject")
SET ObjFSO = CreateObject("Scripting.FileSystemObject")
'
' **************************************************:
' FILE DIRECTORIES TO BE PURGED :
' **************************************************:
SET MEDIA = FileSystem.GetFolder("\\JBALLARD-9520\C$\Users\jballard\Pictures")
SET MEDIA2 = FileSystem.GetFolder("\\JBALLARD-9520\C$\Users\jballard-admin\Pictures")
SET DOWNLOAD = FileSystem.GetFolder("\\JBALLARD-9520\C$\Windows\SoftwareDistribution\DOWNLOAD")
SET ENVTEMP = FileSystem.GetFolder("\\JBALLARD-9520\C$\Users\jballard\AppData\Local\TEMP")
SET ENVTEMP2 = FileSystem.GetFolder("\\JBALLARD-9520\C$\Users\jballard-admin\AppData\Local\TEMP")
SET ENVTEMP3 = FileSystem.GetFolder("\\JBALLARD-9520\C$\Users\Administrator\AppData\Local\TEMP")
SET TEMP = FileSystem.GetFolder("\\JBALLARD-9520\C$\Windows\TEMP")
SET PREFETCH = FileSystem.GetFolder("\\JBALLARD-9520\C$\Windows\PREFETCH")
SET LOGS = FileSystem.GetFolder("\\JBALLARD-9520\C$\0_SVN\7_LOGS\BACKUP")
'
WSCRIPT.ECHO "" & date & ": " & time & " - " & " NOTICE - PURGING WIN SYSTEM OF ALL CLUTTER: "
'
' **************************************************:
' CHECK IF SOFTWARE DISTRIBUTION DIRECTORY EXISTS :
' **************************************************:
If FileSystem.FolderExists(MEDIA) Then
' DELETE ALL ROOT FILES:
For Each FLDR In MEDIA.Files
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(MEDIA), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & MEDIA & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & MEDIA & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
' DELETE SUBFOLDERS & FILES:
For Each FLDR In MEDIA.SubFolders
On Error Resume Next
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(MEDIA), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & MEDIA & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & MEDIA & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
End If
'
If FileSystem.FolderExists(MEDIA2) Then
' DELETE ALL ROOT FILES:
For Each FLDR In MEDIA2.Files
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(MEDIA2), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & MEDIA2 & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & MEDIA2 & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
' DELETE SUBFOLDERS & FILES:
For Each FLDR In MEDIA2.SubFolders
On Error Resume Next
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(MEDIA2), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & MEDIA2 & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & MEDIA2 & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
End If
'
' **************************************************:
' CHECK IF DOWNLOAD DIRECTORY EXISTS :
' **************************************************:
If FileSystem.FolderExists(DOWNLOAD) Then
' DELETE ALL ROOT FILES:
For Each FLDR In DOWNLOAD.Files
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(DOWNLOAD), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & DOWNLOAD & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & DOWNLOAD & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
' DELETE SUBFOLDERS & FILES:
For Each FLDR In DOWNLOAD.SubFolders
On Error Resume Next
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(DOWNLOAD), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & DOWNLOAD & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & DOWNLOAD & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
End If
'
' **************************************************:
' CHECK IF APPDATA DIRECTORY EXISTS :
' **************************************************:
If FileSystem.FolderExists(ENVTEMP) Then
' DELETE ALL ROOT FILES:
For Each FLDR In ENVTEMP.Files
NAME = FLDR.NAME
ObjFSO.DeleteFile(ENVTEMP), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
' DELETE SUBFOLDERS & FILES:
For Each FLDR In ENVTEMP.SubFolders
On Error Resume Next
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(ENVTEMP), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
End If
'
If FileSystem.FolderExists(ENVTEMP2) Then
' DELETE ALL ROOT FILES:
For Each FLDR In ENVTEMP2.Files
NAME = FLDR.NAME
ObjFSO.DeleteFile(ENVTEMP2), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP2 & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP2 & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
' DELETE SUBFOLDERS & FILES:
For Each FLDR In ENVTEMP2.SubFolders
On Error Resume Next
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(ENVTEMP2), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP2 & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP2 & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
End If
'
If FileSystem.FolderExists(ENVTEMP3) Then
' DELETE ALL ROOT FILES:
For Each FLDR In ENVTEMP3.Files
NAME = FLDR.NAME
ObjFSO.DeleteFile(ENVTEMP3), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP3 & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP3 & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
' DELETE SUBFOLDERS & FILES:
For Each FLDR In ENVTEMP3.SubFolders
On Error Resume Next
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(ENVTEMP3), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP3 & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & ENVTEMP3 & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
End If
'
' **************************************************:
' CHECK IF TEMP DIRECTORY EXISTS :
' **************************************************:
If FileSystem.FolderExists(TEMP) Then
' DELETE ALL ROOT FILES:
For Each FLDR In TEMP.Files
NAME = FLDR.NAME
'FLDR.Delete TRUE
ObjFSO.DeleteFile(TEMP), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & TEMP & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & TEMP & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
' DELETE SUBFOLDERS & FILES:
For Each FLDR In TEMP.SubFolders
On Error Resume Next
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(TEMP), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & TEMP & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & TEMP & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
End If
'
' **************************************************:
' CHECK IF PREFETCH DIRECTORY EXISTS :
' **************************************************:
If FileSystem.FolderExists(PREFETCH) Then
' DELETE SUBFOLDERS & FILES:
For Each FLDR In PREFETCH.SubFolders
On Error Resume Next
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(PREFETCH), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & PREFETCH & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & PREFETCH & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
' DELETE ALL ROOT FILES:
For Each FLDR In PREFETCH.Files
NAME = FLDR.NAME
ObjFSO.DeleteFile(PREFETCH), DeleteReadOnly
'ObjFSO.DeleteFile(PREFETCH & \*.pf), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & PREFETCH & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & PREFETCH & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
End If
'
' **************************************************:
' CHECK IF LOGS DIRECTORY EXISTS :
' **************************************************:
If FileSystem.FolderExists(LOGS) Then
' DELETE SUBFOLDERS & FILES:
For Each FLDR In LOGS.SubFolders
On Error Resume Next
NAME = FLDR.NAME
FLDR.Delete TRUE
ObjFSO.DeleteFile(LOGS), DeleteReadOnly
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & LOGS & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & LOGS & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
' DELETE ALL ROOT FILES:
For Each FLDR In LOGS.Files
NAME = FLDR.NAME
ObjFSO.DeleteFile(LOGS), DeleteFile
If Err Then
ObjectLog.WriteLine "" & date & ": " & time & " - " & LOGS & " - " & NAME & " - " & "PURGING ERROR:"
Else
ObjectLog.WriteLine "" & date & ": " & time & " - " & LOGS & " - " & NAME & " - " & "PURGED:"
End If
On Error GoTo 0
Next
End If
'
WSCRIPT.ECHO "" & date & ": " & time & " - " & " SUCCESS - PURGED WIN SYSTEM OF ALL CLUTTER: "
'
' **************************************************:
' END OF SCRIPT :
' **************************************************: