如何从vbs以pipe理员身份运行vbs?

任何人都可以帮助我从自己运行的VBS但具有pipe理员权限? 我需要通过vbs重命名Win8的计算机,但只有通过pipe理员命令行(cmd – >以pipe理员身份运行 – > runScript.vbs)运行我的脚本才有可能。 如果我启动脚本与经典的CMD电脑不重命名。

我的想法是我启动用户权限的脚本,没有参数,如果没有参数,脚本运行自己的pipe理权限和参数作为标识符“我是pipe理员”。

有谁知道我怎么能做到这一点? 谢谢。 McAndy

编辑:

我试过这个:

If WScript.Arguments.Count = 0 Then Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "wscript.exe", "c:\Users\admin\Documents\selfConfigure.vbs -1", "", runas", 1 End If 

如果在计算机上启用了UAC,则应该这样工作:

 If Not WScript.Arguments.Named.Exists("elevate") Then CreateObject("Shell.Application").ShellExecute WScript.FullName _ , """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1 WScript.Quit End If 'actual code 

将其添加到文件的开头:

 Set WshShell = WScript.CreateObject("WScript.Shell") If WScript.Arguments.Length = 0 Then Set ObjShell = CreateObject("Shell.Application") ObjShell.ShellExecute "wscript.exe" _ , """" & WScript.ScriptFullName & """ RunAsAdministrator", , "runas", 1 WScript.Quit End if 

好的文章提升选项 – http://www.novell.com/support/kb/doc.php?id=7010269

配置应用程序始终请求提高权限:

程序可以配置为始终通过HKCU下的注册表设置请求用户级别的提升。 这些注册表设置在运行中是有效的,因此可以在启动特定应用程序之前立即设置它们,并且如果需要,则在应用程序启动后立即移除它们。 只需在“HKCU \ Software \ Microsoft \ Windows NT \ CurrentVersion \ AppCompatFlags \ Layers”下创建一个“字符串值”,即可获得值为“RUNASADMIN”的可执行文件的完整路径。 以下是CMD的一个例子。

 Windows Registry Editor Version 5.00 [HKEY_Current_User\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers] "c:\\windows\\system32\\cmd.exe"="RUNASADMIN" 

乐lil批处理文件

 @set E=ECHO &set S=SET &set CS=CScript //T:3 //nologo %~n0.vbs /REALTIME^>nul^& timeout 1 /NOBREAK^>nul^& del /Q %~n0.vbs&CLS @%E%off&color 4a&title %~n0&%S%CX=CLS^&EXIT&%S%BS=^>%~n0.vbs&%S%G=GOTO &%S%H=shell&AT>NUL IF %ERRORLEVEL% EQU 0 ( %G%2 ) ELSE ( if not "%minimized%"=="" %G%1 ) %S%minimized=true & start /min cmd /C "%~dpnx0"&%CX% :1 %E%%S%%H%=CreateObject("%H%.Application"):%H%.%H%Execute "%~dpnx0",,"%CD%", "runas", 1:%S%%H%=nothing%BS%&%CS%&%CX% :2 %E%%~dpnx0 fvcLing admin mode look up&wmic process where name="cmd.exe" CALL setpriority "realtime"& timeout 3 /NOBREAK>nul :3 %E%x=msgbox("end of line" ,48, "%~n0")%BS%&%CS%&%CX% 

`我的vbs文件路径:

D:\ QTP Practice \ Driver \ Testany.vbs'

 objShell = CreateObject("Shell.Application") objShell.ShellExecute "cmd.exe","/k echo test", "", "runas", 1 set x=createobject("wscript.shell") wscript.sleep(2000) x.sendkeys "CD\"&"{ENTER}"&"cd D:"&"{ENTER}"&"cd "&"QTP Practice\Driver"&"{ENTER}"&"Testany.vbs"&"{ENTER}" 

– 从谷歌搜索和一些调整,为我工作