Lock the system after a long period of no operation

Source: Internet
Author: User

Using system; <br/> using system. collections. generic; <br/> using system. componentmodel; <br/> using system. data; <br/> using system. drawing; <br/> using system. text; <br/> using system. windows. forms; </P> <p> using system. runtime. interopservices; </P> <p> namespace autolock <br/> {<br/> Public partial class form1: Form <br/>{< br/> Public form1 () <br/>{< br/> initializecomponent (); </P> <p >}</P> <p> [structl Ayout (layoutkind. sequential)] <br/> public struct lastinputinfo <br/> {<br/> [financialas (unmanagedtype. u4)] <br/> Public int cbsize; <br/> [financialas (unmanagedtype. u4)] <br/> Public uint dwtime; <br/>}< br/> [dllimport ("user32.dll")] <br/> Public static extern bool getlastinputinfo (ref lastinputinfo plii); </P> <p> Public long getidletick () <br/>{< br/> lastinputinfo vlastinputinfo = new lastinpu Tinfo (); <br/> vlastinputinfo. cbsize = marshal. sizeof (vlastinputinfo); <br/> If (! Getlastinputinfo (ref vlastinputinfo) return 0; <br/> return environment. tickcount-(long) vlastinputinfo. dwtime; <br/>}< br/> // make sure the timer status is available <br/> private void timereffectick (Object sender, eventargs E) <br/>{< br/> long I = getidletick (); <br/> label1.text = I. tostring (); <br/> if (I> 10*1000) <br/> {<br/> // lockwindows (); <br/> lockworkstation (); <br/>}</P> <p> [dllimport ("user32.dll")] <br/> Private Static extern void lockworkstation (); <br/> Public void lockwindows () {<br/> // system. diagnostics. PROCESS p = new system. diagnostics. process (); <br/> // P. startinfo. workingdirectory = system. environment. getfolderpath (environment. specialfolder. system); <br/> // P. startinfo. filename = "rundll32.exe"; <br/> // P. startinfo. arguments = "user32.dll, lockworkstation"; <br/> // P. start (); <br/>}< br/>}

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.