查看远程机器上运行的服务的状态
条件是 - 我没有管理员权限 - 我想查看远程计算机(服务器)中服务的状态
我使用以下代码(带有框架2.0的vb.net)来查看状态
Dim sqlSvc As ServiceController
Svc = New ServiceController(My.Settings.serviceName, My.Settings.machineName)
If sqlSvc.Status.ToString.Equals("Running") Then
displayStatus("success", sqlSvc.Status.ToString)
Else
displayStatus("error", sqlSvc.Status.ToString)
End If
运行代码时,引发并发现InvalidOperationException
发现我需要在服务器中进行管理。
我可以在远程计算机上没有管理员权限的情况下查找服务的状态吗?
The conditions are
- I don't have administrator privilege
- I want to see the status of a service in remote machine (server)
I use the following code (vb.net with framework 2.0) to see the status
Dim sqlSvc As ServiceController
Svc = New ServiceController(My.Settings.serviceName, My.Settings.machineName)
If sqlSvc.Status.ToString.Equals("Running") Then
displayStatus("success", sqlSvc.Status.ToString)
Else
displayStatus("error", sqlSvc.Status.ToString)
End If
When running the code, InvalidOperationException
is raised and found out that I need admin right in the server.
Can I lookup the status of the service without having admin right in remote machine ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必是远程计算机上的管理员,但您至少需要对要监视的特定服务具有 SERVICE_QUERY_STATUS 权限。本地管理员组和高级用户组都有此功能。或者,您可以创建一个组并使用 subinacl.exe 或 安全模板
You don't have to be admin on remote machine, but you do need at least SERVICE_QUERY_STATUS permission on the particular service you want to monitor. The local Administrators group has this, as does Power Users. Or you can create a group and grant it the permission with subinacl.exe or Security Templates
您可能会从此调用中获得两种类型的
System.InvalidOperationException
:在计算机“{Y}”上找不到服务 {X}
或无法打开服务控制计算机“{Y}”上的管理员。此操作可能需要其他权限
。第一个来自无效的服务名称,第二个来自您没有权限或更可能找不到计算机名称。另外,除非必要,否则不要使用 ToString()。你有一个枚举,使用它:
You can get two types of
System.InvalidOperationException
from this call, eitherService {X} was not found on computer '{Y}'
orCannot open Service Control Manager on computer '{Y}'. This operation might require other privileges
. The first comes from an invalid service name and the second comes when either you don't have permission or more likely the machine name can't be found.Also, don't use ToString() unless you have to. You've got an enum, use it: