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
There is one way you can programmatically login to windows without using credential providers. Follow the following steps:
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.
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.
Set the window state property of the form as "maximized".
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.
Create the exe file of your application.
Now open the registry editor and locate to path:
HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Windows > CurrentVersion >Winlogon.
Replace the path of userinit attribute with your exe file of your application as shown in the above picture.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With