Admin.vbs the VBS command that runs the program as an administrator _dos/bat

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.