Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,

I am trying to make an app which does the following.

When a user logs in to Windows I want my app to run. Can someone help me how to figure out when a user logs in to windows by typing their credentials and let my app know.

I am thinking putting my app to startup folder and make a timer check the login process every second or by the given interval. It will be also nice to give me a reference link how to check the login?

Is that a correct path to overcome this problem? I would appreciate if someone lead me the way. Thanks in advance.
Posted
Updated 17-Sep-14 4:40am
v2
Comments
[no name] 17-Sep-14 11:00am    
You are putting the cart before the horse. If you put your app in the startup folder, you will know that the user has logged into Windows because your application will startup.
[no name] 17-Sep-14 11:29am    
I thing the correct way to do this would be to use a service. Services are the first thing that run on Windows.

Use the Windows Task Scheduler, and add a trigger to run your task when a user logs in.
http://technet.microsoft.com/en-us/library/cc748841.aspx[^]
 
Share this answer
 
Comments
CPallini 17-Sep-14 11:06am    
Wow, nice. My 5.
Sergey Alexandrovich Kryukov 17-Sep-14 11:46am    
I voted 5, too, but, for completeness, added one alternative solution.
—SA
wonder-FOOL 18-Sep-14 2:16am    
Thanks that is the most practical answer IMO.
Alternative to Solution 1:

You can develop your own Windows Service, by whatever reason. In that service, you can handle system events using the class Microsoft.Win32.SystemEvents:
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents%28v=vs.110%29.aspx[^].

The event you would need to handle is SessionSwitch:
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionswitch(v=vs.110).aspx[^].

If has to be the Windows Service applicaiton, because your application should be already running when a user logs on. Please see:
http://en.wikipedia.org/wiki/Windows_service[^],
http://msdn.microsoft.com/en-us/library/d56de412(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/y817hyb6%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
v2
Comments
CPallini 17-Sep-14 11:55am    
5.
Sergey Alexandrovich Kryukov 17-Sep-14 12:20pm    
Thank you, Carlo.
—SA
[no name] 17-Sep-14 12:38pm    
Rated 5 stars, and they were also some of the resources I was trying to find when I suggested this method in the comments section above. Again my vote, 5 +
Sergey Alexandrovich Kryukov 17-Sep-14 12:57pm    
Thank you very much.
—SA
wonder-FOOL 18-Sep-14 2:18am    
Thank you Sergey. I find Richard's answer more practical and less time consuming in my current schedule. But your answer also makes sense. I appreciate the help and your time spent on answering my question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900