【发布时间】:2014-12-12 08:55:07
【问题描述】:
Synergy 1.6.2 似乎与我使用的另一个实用程序 (ActualTools) 发生冲突,当我等待他们找出是谁的错时,一个简单的解决方法是在出现问题时重新启动 Synergy 服务。为了节省每次都手动执行此操作,我改编了this 脚本。在调用它时,我只是从 StopService 函数中得到“错误 2”——它对应于“用户没有必要的访问权限”。这看起来很奇怪,因为我可以运行compmgmt.msc(就像我登录的身份,而不是管理员身份)并在那里手动重新启动服务,而不会出现任何问题或请求额外的凭据。但是,我不能在命令行中使用net stop Synergy - 我得到系统错误 5(访问被拒绝)。所以,我想这与权限/特权有关。
我尝试过修改该脚本中的这一行:
Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
通过引用特权列表here - 例如,将(Tcb) 添加到安全名字对象。但是我不确定那是正确的方法,而且我无论如何也找不到与服务管理相对应的权限。
那么,在这种情况下,有没有办法通过脚本获得正确的权限来停止/启动服务?作为参考,这里是完整的脚本:
Dim cimv2, oService, Result
'Get the WMI administration object
Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
'Get the service object
Set oService = cimv2.Get("Win32_Service.Name='Synergy'")
If Not oService.Started Then
' the service is Not started
wscript.echo "Synergy is not started"
wscript.quit
End If
If Not oService.AcceptStop Then
' the service does Not accept stop command
wscript.echo "Synergy does not accept stop command"
wscript.quit
End If
'Stop the service
Result = oService.StopService
If 0 <> Result Then
wscript.echo "Stop Synergy error: " & Result
wscript.quit
End If
Do While oService.Started And Wait
'get the current service state
Set oService = cimv2.Get("Win32_Service.Name='Synergy'")
Wscript.Sleep 200
Loop
If oService.Started Then
' the service is Not started
wscript.echo "Synergy is already running."
wscript.quit
End If
'Start the service
Result = oService.StartService
If 0 <> Result Then
wscript.echo "Start Synergy error:" & Result
wscript.quit
End If
Do While InStr(1,oService.State,"running",1) = 0 And Wait
'get the current service state
Set oService = cimv2.Get("Win32_Service.Name='Synergy'")
Wscript.Sleep 200
Loop
【问题讨论】:
标签: vbscript windows-services wmi wsh