Making Sure A Service Doesn't Start For Other Users

Hey everyone

I have created a service for myself to start various processes upon logon.  I know that I could have just added a registry value, but I fancied doing it via code, that way I can take the service with me and create logs etc.

What I don't want is for the process to start for anybody other than myself, so I thought about putting the following code in the OnStart method:

if (WindowsIdentity.GetCurrent().Name.ToString() == myUserName)

However when I done a quick test on a normal Windows App I found that the form would initially load, then exit.  As there is a good deal of processing within my code I really dont want it to do anything unless it's me who is logged in.  Is there anyway that I can make sure that it won't activate any other code unless I'm the logged in user?
LVL 15
angus_young_acdcAsked:
Who is Participating?
 
daveamourConnect With a Mentor Commented:
Services start when the pc/server boots up and wil run even if non one logs on.  If they didn't work like this then thye would be no good and nothing would work!
With this in mind does your question make any sense?
0
 
angus_young_acdcAuthor Commented:
I think it does.  I want it to automatically run when the PC boots, I just don't want any of the processing to happen unless its me that has logged in.
0
 
daveamourConnect With a Mentor Commented:
Ok I see.
In that case your service should start and then start an infinite loop where it periodically checks the logged on user and if it is you then go and run whatever code.
Would that suit your needs?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.