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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
| ' FS and common functions library.
' by AllFree.
option explicit
dim ScriptPath, ScriptName, ScriptFullName, fso, wshl, nat, drives
set fso = createobject("scripting.filesystemobject")
set wshl = createobject("wscript.shell")
set nat = createobject("wscript.network")
set drives=fso.drives
ScriptPath=fso.getparentfoldername(wscript.scriptfullname)
ScriptName=Wscript.ScriptName
ScriptFullName=Wscript.ScriptFullName
function GetCommandLine()
on error resume next
dim args,arg, i
set args = WScript.Arguments
for i = 0 to Args.Count - 1
GetCommandLine=GetCommandLine & args(i)
if i < args.count-1 then GetCommandLine=GetCommandLine & arg & " "
next
end function
function RegWriteValue(KEYname,value, vtype)
on error resume next
err.clear
wshl.regwrite KEYname,value
RegWriteValue=(err.number=0)
end function
function RegReadValue(KEY,byref buff)
on error resume next
err.clear
buff=""
buff=wshl.regread(key)
RegRead=(err.number=0)
end function
function RegDelete(key)
on error resume next
err.clear
wshl.regdelete key
RegDetete=(err.number=0)
end function
function KeyExists(KEY)
on error resume next
err.clear
if Right(KEY,1) <> "" then KEY=KEY & ""
wshl.regread KEY
KeyExists=(err.number=0)
end function
function GetArgsCount()
on error resume next
dim args
set args=wscript.arguments
GetArgsCount=args.count
end function
function GetFileSize(path)
on error resume next
err.clear
GetFileSize=fso.getfile(path).size
if err.number <> 0 then GetFileSize=-1
end function
sub Sleep(mSec)
wscript.sleep msec
end sub
function GetScriptSrc()
on error resume next
err.clear
dim s, txt
set s=fso.getfile(wscript.scriptfullname).OpenAsTextStream(1)
GetScriptSrc=s.ReadAll()
s.close
end function
function GetWinDir()
on error resume next
err.clear
GetWinDir=GetSystemFolder(0)
end function
function GetSysDir()
on error resume next
err.clear
GetSysDir=GetSystemFolder(1)
end function
function GetTempDir()
on error resume next
err.clear
GetTempDir=GetSystemFolder(2)
end function
function GetOsType
On Error Resume Next
err.clear
GetOsType=""
dim objWMIService, colItems, objItem
set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", &h10+&h20)
for each objitem in colitems
GetOsType=objItem.Caption
exit for
next
set objWMIService=nothing
set colItems=nothing
end function
function DeleteFile(path)
on error resume next
err.clear
dim fn
set fn=fso.getfile(path)
fn.attributes=0
fn.delete
DeleteFile=(err.number=0)
end function
function DeleteFolder(path)
on error resume next
err.clear
fso.deletefolder path
DeleteFolder=(err.number=0)
end function
function StripSlash(path)
on error resume next
err.clear
StripSlash=path
if right(StripSlash,1)="" then StripSlash=mid(StripSlash,1, len(StripSlash)-1)
end function
function WriteFile(filename, buff, ovw)
on error resume next
err.clear
dim c
set c=fso.createtextfile(filename,ovw)
c.write buff
c.close
set c=nothing
WriteFile=(err.number=0)
end function
function WriteFileEx(filename, buff)
on error resume next
err.clear
dim pt
WriteFileEx=false
pt=getfilepath(filename)
if not ForcePath(pt) then exit function
SureCreateTo=writefile(filename, buff, true)
end function
function ReadLine(filename)
on error resume next
err.clear
dim c,s
ReadLine=""
set c=fso.getfile(filename)
set s=c.openastextstream(1)
buff=s.readline
s.close
set c=nothing
set s=nothing
end function
function ReadFile(filename, byref buff)
on error resume next
err.clear
dim c,s
buff=""
set c=fso.getfile(filename)
set s=c.openastextstream(1)
buff=s.readall
s.close
set c=nothing
set s=nothing
ReadFile=(err.number=0)
end function
function CompareStr(str1,str2)
CompareStr=(lcase(str1)=lcase(str2))
end function
function CreateShortCut(shpath,target,icon)
on error resume next
err.clear
dim lnk
set lnk=wshl.createshortcut(shpath)
lnk.targetpath=target
lnk.iconlocation=icon
lnk.save
set lnk=nothing
CreateShortCut=(err.number=0)
end function
function SetAttr(file,attrs)
on error resume next
err.clear
if fileexists(file) then
fso.getfile(file).attributes=attrs
elseif folderexists(file) then
fso.getfolder(file).attributes=attrs
end if
SetAttr=(err.number=0)
end function
function RunProgram(cmdline,state)
on error resume next
err.clear
wshl.run cmdline,state
RunProgram=(err.number=0)
end function
function GetSystemFolder(index)
on error resume next
err.clear
GetSystemFolder=fso.getspecialfolder(index)
if GetSystemFolder <> "" then GetSystemFolder=BackSlash(GetSystemFolder)
end function
function GetSpecialFolder(name)
on error resume next
err.clear
GetSpecialFolder=wshl.specialfolders(name)
if GetSpecialFolder <> "" then GetSpecialFolder=BackSlash(GetSpecialFolder)
end function
function CreateFolder(path)
on error resume next
err.clear
fso.CreateFolder path
CreateFolder=(err.number=0 or err.number=58)
end function
function ForcePath(path)
on error resume next
err.clear
dim c
ForcePath=true
path=StripSlash(path)
if len(path)<3 or folderexists(path) or getfilepath(path)=path then exit function
ForcePath=ForcePath(GetFilePath(path)) and CreateFolder(path)
end function
function BackSlash(path)
if right(path,1) <> "" then path = path & ""
BackSlash=path
end function
function CopyFile(path,dest)
on error resume next
err.clear
fso.copyfile path,dest
CopyFile=(err.number=0)
end function
function CopyFileEx(path,dest)
on error resume next
err.clear
dim pt
CopyFileEx=false
pt=getfilepath(dest)
if not ForcePath(pt) then exit function
CopyFileEx=copyfile(path,dest)
end function
function MoveFile(path,dest)
on error resume next
err.clear
fso.movefile path,dest
MoveFile=(err.number=0)
end function
function MoveFileEx(path,dest)
on error resume next
err.clear
if not ForcePath(dest) then exit function
fso.movefile path,dest
MoveFileEx=(err.number=0)
end function
function RenameFile(filename,newname)
on error resume next
err.clear
RenameFile=MoveFile(filename,newname)
end function
function FileExists(path)
on error resume next
err.clear
FileExists=fso.fileexists(path)
end function
function FolderExists(path)
on error resume next
err.clear
FolderExists=fso.folderexists(path)
end function
function GetFileDrive(path)
on error resume next
err.clear
GetFileDrive=fso.getdrivename(path)
end function
function GetFilePath(path)
on error resume next
err.clear
GetFilePath=fso.getparentfoldername(path)
end function
function GetFileName(path)
on error resume next
dim s
err.clear
GetFileName=fso.getfilename(path)
end function
function GetFileExt(path)
on error resume next
err.clear
dim tmp
tmp=fso.getextensionname(path)
if tmp <> "" then tmp="." & tmp
GetFileExt=tmp
end function
function ChangeFileExt(path,newext)
on error resume next
err.clear
ChangeFileExt=""
if path="" or newext="" then exit function
ChangeFileExt=backslash(getfilepath(path)) & fso.getbasename(path) & newext
end function
function BuildPath(path, name)
on error resume next
err.clear
BuildPath=fso.BuildPath(path, name)
end function
function RandomRng(afrom, ato)
Randomize()
RandomRng=CInt(Int((ato * Rnd()) + afrom))
while RandomRng >ato
RandomRng=RandomRng-1
wend
while RandomRng <afrom
RandomRng=RandomRng+1
wend
end function
function EncodeText(text)
on error resume next
err.clear
dim s, enc
set enc=CreateObject("Scripting.Encoder")
text=enc.EncodeScriptFile(".vbs", text, 0, "")
EncodeText=text
end function
Function PrevInstance()
On Error Resume Next
Dim btRQORm, YLjhBU, mpQ, otMTvP, LRh, IMd
otMTvP=0
IMd=Wscript.ScriptFullName
Set mpQ=GetObject("winmgmts:\\.\root\CIMV2")
Set YLjhBU = mpQ.ExecQuery("SELECT * FROM Win32_Process", "WQL", &h10+&h20)
For Each btRQORm in YLjhBU
If Lcase(btRQORm.Name)="wscript.exe" Then
LRh=Replace(btRQORm.CommandLine,Chr(34),"")
LRh=Right(Trim(LRh),len(IMd))
If Lcase(LRh)=Lcase(IMd) Then otMTvP=otMTvP+1
End If
Next
PrevInstance=(otMTvP>1)
End Function
if PrevInstance() Then Wscript.Quit
sub Quit()
Wscript.Quit()
end sub
function RndName()
on error resume next
err.clear
dim s,i
for i=1 to 6
RndName=RndName & Chr(RandomRng(65,90))
next
end function |