Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
827 views
in Technique[技术] by (71.8m points)

windows - Unlock local computer using .net

Is there any way, without using DLL injection, services, and whatnot, to unlock the local computer using .net? The windows username and password is available to my program.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think there is no .NET function that you can use to unlock your computer and there is no short way to achieve it. But there is a way.

You need to implement your custom ICredentialProvider componet, hook it into the windows authentication mechanism, and implement communication between it and your application.

The Windows 7 authentication mechanism consists of two parts. They are WinLogon and LogonUI. LogonUI is responsible for displaying a login window and notification of WinLogon about users’ actions. Winlogon reacts for events from LogonUI and performs required actions to log-in users, log-off users, lock sessions, and unlock sessions.

Microsoft provides a mechanism to hook a custom behavior into LogonUI. To do this you need to create a COM object that implements ICredentialProvider and register it with a system. You component can tell LogonUI to tell WinLogon to unlock a session.

Here are couple examples of how to build custom credential providers: How to Build Custom Logon UI’s in Windows Vista, Create Custom Login Experiences With Credential Providers For Windows Vista

This mechanism will work for Windows Vista and Windows 7. You need to use similar mechanism called GINA if you want to achieve the same result for Windows XP. Here you can read more about GINA: Winlogon and GINA

There was a hack that you could kind of “unlock” a session in Windows XP.

WinLogon in Windows XP created an additional desktop and switched to it when user chose to lock a session. It was possible to switch back to a “normal” desktop using Windows API. Everything worked fine except WinLogon still though that system is locked and did not react for Ctrl-Alt-Del. I believe that it will not work for Windows Vista and 7. But you could try. It can be simple than implementing a custom credential provider.

Here is an example of how to do that: Remotely Unlock a Windows Workstation

I hope this answered your question.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...