In some C # Windows applications, You need to lock your computer when the user leaves temporarily. This is a simple solution. Set screen saver of the computer to "password-protected upon recovery", and call the screen saver of the system in the application.
Advantages: The implementation is simple and practical.
Disadvantages: 1. the user's computer needs to use screen protection in advance and set it to "use password protection during recovery" mode.
2. the user of the computer must set a safe logon password for the System user of the local machine.
For disadvantage 1, you can consider Automatic Detection settings during application startup (in fact, some operations on the system registry ). For drawback 2, I think it is necessary to run a computer with a key task. Otherwise, no screen lock operation is required.
Implementation: Create the startup form test. CS:
Article Source: http://www.diybl.com/course/4_webprogram/asp.net/netjs/2008913/142591.html
- Using system;
- Using system. Collections. Generic;
- Using system. componentmodel;
- Using system. Data;
- Using system. drawing;
- Using system. text;
- Using system. Windows. forms;
- Using system. runtime. interopservices;
- Namespace ttmisadmin
- {
- Public partial class test: Form
- {
- Public test ()
- {
- Initializecomponent ();
- }
- [Dllimport ("user32.dll")]
- Public static extern bool sendmessage (intptr hwnd, int wmsg, int wparam, int lparam );
- Public const int wm_syscommand = 0x0112;
- Public const int SC _screensave = 0xf140;
- Private void button#click (Object sender, eventargs E)
- {
- // Start the Screen Saver
- Sendmessage (this. Handle, wm_syscommand, SC _screensave, 0 );
- }
- }
- }