Admin. vbs run the vbs command of the program as an administrator

Source: Internet
Author: User

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.

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.