c# - Monitoring Windows service status remotely as non-administrator? -
background: have application that, among other parts of back-end, uses server-side windows service of computation.
what i'm trying display status of service (running vs. stopped, essentially) on client, such users can know (a) if background computation happening, or (b) if need go poke guy check server. (it's written sme customer doesn't have full-time department or budget wants spent on fancy service-monitoring-and-alerting software.)
in itself, that's easy enough servicecontroller - if you're administrator on server, users, of course, aren't. there way read service status remote server in .net non-administrative user? (all need read status; don't need, , don't want, give users rights stop/restart/alter service in way.)
if user under application works doesn't have sufficient permissions accessing services, you're error this:
service.status threw exception of type 'system.invalidoperationexception' cannot open myservice service on computer '192.168.0.7'. access denied. you need switch user context able monitor it. if don't want entire application (which rather obvious), try impersonation actual piece of code status checking. should user? safety reasons, shouldn't user has access entire machine. should has access controlling services. ask administrator create such user you. status monitoring can executed this:
public string getservicestatus(string machine, string service) { return impersonate( () => { var service = new servicecontroller(machine, service); service.refresh(); return service.status; }, user, domain, password ); } the entire thread detailed solution can found here.
edit:
let me explain topic further. solution i've provided gives opportunity change user context, particular piece of code. can whatever want e.g. service status checking. user, under context such operation going executed, can have granted access perform it, or not. it's different story though. it's computer administrator responsibility grant such access. in simplest case can add such user administrators group, reckless, can grant granular access using group policy. more detailed information regarding such administration issues can found here , here.
Comments
Post a Comment