Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could programmatically login into window 7,8 desktop

I would like to know if there is any way to login into an account on a Window 7,8 machine using .NET

For example you have a service which before start doing something (etc automate a window application) you have to login into this account.

edit:

I would like the window service to login into user Dekstop as to be able to run my tasks

like image 279
pagratios Avatar asked Nov 09 '22 05:11

pagratios


1 Answers

There is one way you can programmatically login to windows without using credential providers. Follow the following steps:

  1. Open run type "netplwiz" uncheck the box that says "user must enter a user name and password to use this computer", which ultimately sets windows to auto login.

  2. Create a c# windows login form as shown below. Or simply you can create your form as per requirement as a 3rd party authentication. I have my own login authentication.

    enter image description here

  3. Set the window state property of the form as "maximized".

  4. On the button click event, call the function "Process.Start(@"C:\Windows\system32\userinit.exe");" The userinit.exe is the executable file which runs just after the windows logon event. This exe is located usually in "C:\Windows\system32" location.

  5. Create the exe file of your application.

  6. Now open the registry editor and locate to path:

HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Windows > CurrentVersion >Winlogon.

enter image description here

  1. Replace the path of userinit attribute with your exe file of your application as shown in the above picture.

  2. Now restart your computer once the auto login completes the winform application is launched as in my case "Login Authentication" form created by me as shown in the picture. Once I enter the username and password, then click on Login button it exeutes the userinit.exe and I am redirected to the desktop screen.

So this is one way you can create your third party login form to logon to windows machine as per your application's requirement.

like image 109
Himanshu Dwivedi Avatar answered Nov 15 '22 09:11

Himanshu Dwivedi