Copy Code code as follows:
' Command to run the program as an administrator Admin.vbs
Set objwmiservices = GetObject ("winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2")
Set Objwbemobjectset = Objwmiservices.execquery (_
"SELECT * from Win32_Process WHERE" &_
"Executablepath= '" & Replace (Wscript.fullname, "\", "\") & "' and" & _
"CommandLine like '%" & wscript.scriptname & "%")
For each objwbemobject in Objwbemobjectset
CmdLine = Objwbemobject.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 & vbCrLf _
& "Parameters parameters passed to program" & VbCrLf _
& VbCrLf
WScript.Echo Helpstr
End Function
The proposal puts to the%SystemRoot%\System32 directory, to likes to play CMD and the operating system is Win7 the person to have some use.
Occasionally use some commands (such as reg.exe) requires administrator privileges, directly in CMD admin reg add ... Can.