c# - Use ServiceController and ServiceControllerPermission class to check the status of a service -
i working on application checks status of services running on remote machine. want non-administrative account. logon account launch application can browse , check status of services running on remote machine via "services.msc". using servicecontroller
class query status of service:
servicecontroller controller = new servicecontroller(servicename, machinename); if (controller.status != servicecontrollerstatus.running) { // something. }
when use non-admin account above line fails "access denied" exception. blogs suggested can use servicecontrollerpermission
class check , assert permission on service before executing above code. not exception when try demand
or assert
permission on service.
servicecontrollerpermission permission = new servicecontrollerpermission(servicecontrollerpermissionaccess.browse, machinename, servicename); permission.demand(); permission.assert(); if (controller.status != servicecontrollerstatus.running) { // something. }
there not information on msdn on security requirements servicecontroller
or servicecontrollerpermission
class.
could tell me right way use servicecontroller class check status of service.
Comments
Post a Comment