C # screen lock Solution

Source: Internet
Author: User
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
  1. Using system;
  2. Using system. Collections. Generic;
  3. Using system. componentmodel;
  4. Using system. Data;
  5. Using system. drawing;
  6. Using system. text;
  7. Using system. Windows. forms;
  8. Using system. runtime. interopservices;
  9. Namespace ttmisadmin
  10. {
  11. Public partial class test: Form
  12. {
  13. Public test ()
  14. {
  15. Initializecomponent ();
  16. }
  17. [Dllimport ("user32.dll")]
  18. Public static extern bool sendmessage (intptr hwnd, int wmsg, int wparam, int lparam );
  19. Public const int wm_syscommand = 0x0112;
  20. Public const int SC _screensave = 0xf140;
  21. Private void button#click (Object sender, eventargs E)
  22. {
  23. // Start the Screen Saver
  24. Sendmessage (this. Handle, wm_syscommand, SC _screensave, 0 );
  25. }
  26. }
  27. }

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.