-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunadm.vbs
52 lines (43 loc) · 1.41 KB
/
runadm.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
' #=======================================================#
' # RUNADM.VBS #
' #=======================================================#
' # Run a specified program with admin rights. #
' # #
' # Copyright(C) ZulNs, Yogyakarta, June 29'th, 2013 #
' #=======================================================#
Option Explicit
Const TITLE = "ZulNs: Run Admin", ADMIN = "adm"
If Wscript.Arguments.Count = 0 Then
MsgBox "Run a program with administrative priveleges.", _
vbInformation, TITLE
Wscript.Quit
End If
Dim params, quote, arg, shell
quote = Chr(34)
For Each arg In Wscript.Arguments
If arg <> ADMIN Then
If InStr(Trim(arg), " ") = 0 Then
params = params & Trim(arg) & " "
Else
params = params & quote & Trim(arg) & quote & " "
End If
End If
Next
Set arg = Nothing
params = Trim(params)
If Wscript.Arguments.Item(0) <> ADMIN Then
Set shell = CreateObject("Shell.Application")
shell.ShellExecute "wscript.exe", _
quote & WScript.ScriptFullName & quote & _
" " & ADMIN & " " & params, "", "runas", 1
Else
Dim retCode
Set shell = CreateObject("Wscript.Shell")
retCode = shell.Run(params, 1, True)
If retCode = 0 Then
MsgBox "DONE.", vbInformation, TITLE
Else
MsgBox "FAILED!!!", vbCritical, TITLE
End If
End If
Set shell = Nothing