User-1020797826 posted
Hi,
I have an app which I use to start and stop services on a local PC. In order to make this work on a remote PC I added in an impersonation class and encapsulated most of my service handling logic inside the higher user account. Well, now
I would like to modify this application so that I can determine before I make the call if I need to impersonate another user. The reason for this is because to now run it locally I have to make sure my impersonation account exists on the local machine, etc.
Lots of extra work for some supposedly portable code.
The only way I thought of to do this was to catch invalidoperationexceptions and throw a custom exception type. But it seems to me this method would result in much duplicate/redundant code where I would have a tryimpersonate() and a trywithoutimpersonate()
for each service query.
So I hope that someone can tell me a quick and easy way to determine whether the impersonate call is necessary. The only service related queries I ever call are serviceprocess.status, start, and stop.