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/>}