查看远程机器上运行的服务的状态

发布于 2024-08-27 22:01:58 字数 494 浏览 3 评论 0原文

条件是 - 我没有管理员权限 - 我想查看远程计算机(服务器)中服务的状态

我使用以下代码(带有框架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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅浅淡淡 2024-09-03 22:01:58

您不必是远程计算机上的管理员,但您至少需要对要监视的特定服务具有 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

⊕婉儿 2024-09-03 22:01:58

您可能会从此调用中获得两种类型的 System.InvalidOperationException在计算机“{Y}”上找不到服务 {X}无法打开服务控制计算机“{Y}”上的管理员。此操作可能需要其他权限。第一个来自无效的服务名称,第二个来自您没有权限或更可能找不到计算机名称。

另外,除非必要,否则不要使用 ToString()。你有一个枚举,使用它:

If sqlSvc.Status = ServiceControllerStatus.Running Then

You can get two types of System.InvalidOperationException from this call, either Service {X} was not found on computer '{Y}' or Cannot 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:

If sqlSvc.Status = ServiceControllerStatus.Running Then
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文