Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unlock Windows programmatically

Tags:

In my current C# code I'm able to lock a Windows user session programmatically (same as Windows + L).

Since the app would still be running, is there any way to unlock the session from that C# program. User credentials are known. The app is running on Windows 7.

like image 673
fdezjose Avatar asked Aug 07 '11 19:08

fdezjose


1 Answers

You'll need a custom windows credential provider to log in for you. Also, you'll need to save the user's credentials somewhere to log in. There are some samples in Windows SDK 7 https://www.microsoft.com/en-us/download/details.aspx?id=8279

There's a bunch of projects to get you started under Samples\security\credentialproviders.

To unlock the screen:

  • set the username / password in CSampleCredential::Initialize
  • set autologin to true in CSampleCredential::SetSelected
  • search the hardware provider sample for WM_TOGGLE_CONNECTED_STATUS message to see how to trigger the login
  • build some way to communicate with your app to trigger the unlock (local tcp server for example)

It's a pain in the ass, but it works.

like image 116
toster-cx Avatar answered Sep 21 '22 15:09

toster-cx