views:

162

answers:

2

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 ?

+1  A: 

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

JC
A: 

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
Chris Haas