Copy codeThe Code is as follows: 'COMMAND admin. vbs for running programs as Administrator
Set ob1_miservices = GetObject ("winmgmts: {impersonationLevel = impersonate }! \. \ Root \ cimv2 ")
Set ob1_bemobjectset = ob1_miservices. ExecQuery (_
"SELECT * FROM Win32_Process WHERE "&_
"ExecutablePath = '" & Replace (WScript. FullName, "\", "\") & "' and "&_
"CommandLine LIKE '%" & WScript. ScriptName & "% '")
For each ob1_bemobject in ob1_bemobjectset
Required line = ob1_bemobject. CommandLine
Next
If WScript. Arguments. Count then
File = WScript. Arguments (0)
If file = "/? "Then
Call ShowHelp ()
WScript. Quit
End if
Set RegEx = new RegExp
RegEx. IgnoreCase = true
RegEx. Global = true
RegEx. pattern = "\\|\/ ||\( |\) |\[ |\] |\{|\}|\^|\$ | \. | \ * | \? | \ +"
Temp1 = RegEx. Replace (WScript. ScriptName, "\ $ &")
Temp2 = RegEx. Replace (file, "\ $ &")
RegEx. Global = false
RegEx. Pattern = "^ .*? "& Temp1 &" ["" \ s] * "& temp2 &"""? \ S *"
Args = RegEx. Replace (cmdline ,"")
'Wscript. Echo file, args
Else
File = "cmd.exe"
'Args = "/k cd/d" & CreateObject ("WScript. Shell"). CurrentDirectory & Chr (34)
End if
'Core code
Set sh = CreateObject ("Shell. Application ")
Call sh. ShellExecute (file, args, "runas ")
Function ShowHelp ()
Dim HelpStr
HelpStr = "run the program as an administrator. "& VbCrLf _
& VbCrLf _
& WScript. ScriptName & "[program] [parameters]..." & vbCrLf _
& VbCrLf _
& "Program to run in program" & vbCrLf _
& "Parameters passed to program parameters" & vbCrLf _
& VbCrLf
WScript. Echo HelpStr
End function
We recommend that you put it in the % SystemRoot % \ system32 directory, which is useful to those who like cmd and the OS is win7.
The administrator privilege is required to use some commands (such as reg.exe). You can directly add admin reg... in cmd.