[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Making Sure A Service Doesn't Start For Other Users

Posted on 2009-02-16
3
Medium Priority
?
165 Views
Last Modified: 2013-12-17
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?
0
Comment
Question by:angus_young_acdc
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
daveamour earned 1500 total points
ID: 23649557
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
 
LVL 15

Author Comment

by:angus_young_acdc
ID: 23649760
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
 
LVL 19

Assisted Solution

by:daveamour
daveamour earned 1500 total points
ID: 23649798
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question