今天是:
设百科问答网为首页|收藏百科问答网|网站地图
百科问答网 - 帮您解决问题,分享成功经验
百科问答网  » 电脑/数码/通讯/互联网 » 操作系统  » Vista中vbs脚本执行WshShell.Run命令时的权限问题

Vista中vbs脚本执行WshShell.Run命令时的权限问题


一个vbs脚本,通过WshShell.Run()来执行一条sc 装载服务的命令,XP下成功。但在Vista中,用sc装载服务时却必须以管理员权限才能成功,假如将这条命令放在CMD脚本中,通过“以管理员身份运行”可以完成,但在vbs脚本中又该如何让这条命令获得管理员权限呢?请求高人指点。


答案或建议:


Method 1

This re-launches the current VBScript as administrator (elevated) if the script has no command-line arguments passed. When re-launching the script as administrator, simply pass a bogus argument so that the script does not run in a cyclic loop.

If WScript.Arguments.length =0 Then
Set objShell = CreateObject("Shell.Application")
'Pass a bogus argument with leading blank space, say [ uac]
objShell.ShellExecute "wscript.exe", Chr(34) & _
WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
'Add your code here
End If

Method 2

This method uses a stub or wrapper script which runs the main VBScript elevated using the runas verb.

Set objShell = CreateObject("Shell.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
strPath = FSO.GetParentFolderName (WScript.ScriptFullName)
If FSO.FileExists(strPath & "\MAIN.VBS") Then
objShell.ShellExecute "wscript.exe", _
Chr(34) & strPath & "\MAIN.VBS" & Chr(34), "", "runas", 1
Else
MsgBox "Script file MAIN.VBS not found"
End If
原文参考:http://www.winhelponline.com/articles/185/1/VBScripts-and-UAC-elevation.html


文章来自:http://www.baikewenda.com/tech/os/8/11/a193476027.htm

推荐内容

敬请注意:百科问答网内容来源于网络或民间经验收集,仅供参考。其中有关健康疾病方面的内容请务必咨询专业医生或及时到医院治疗。
关于我们 - 广告服务 - 联系我们
百科问答网 Copyright ©2005 - 2011 www.baikewenda.com,All Rights Reserved
辽ICP备10007180号