Video Screencast Help

NoSleep.exe - Prevents Screensaver and PC Locking

Created: 22 Jul 2009 • Updated: 29 Jul 2010 | 21 comments
Mike.Langford's picture
+10 10 Votes
Login to vote

I wrote a little utility that runs in your system tray and prevents your computer from locking or going into screensaver mode as it normally would when idle and while it is not really Symantec related, I have found it very useful and I thought I would share it.

Why would you want to prevent this you ask?

Well, I work on two PCs and group policy sets our screensaver and locking timeout. Quite often I would be working on PC1 for a few minutes and then PC2 would lock, so when I want to go back to PC2, I would unlock it. Then while I am on PC2, PC1 would lock. I found myself unlocking my PCs several times a day and it started to get annoying. I am all in favor of security and still lock my PCs when I leave my desk, but this little utility keeps them active while I am sitting here.

How does it work?

It is very simple. All it does is move your mouse one pixel to the left, and then one pixel to the right every 30 seconds. This tiny bit of movement is invisible to the user, but is enough to make Windows think that someone is using the PC.

While running, you will see this icon in your system tray:

imagebrowser image

If you want to exit the utility, simply right click it and click "Exit"

Comments 21 CommentsJump to latest comment

KSchroeder's picture

I've thought about making something that does exactly what you're doing here, but never knew enough Windows programming to do it.  Nice work!

Thanks,
Kyle
Symantec Trusted Advisor

For Forum threads, please click "Mark as Solution" if answered.
For all content, please give a thumbs up if you agree with or support the post.

+1
Login to vote
ktran's picture

This is a nice utility, what language do you use to create this?

+1
Login to vote
Mike.Langford's picture

It is an easy little scriping language called AutoIt.  Similar to VB Script, but it has GUI functionallity, and compiles to an EXE which is kind of handy.

Only about 30 lines of code total, most of which is setting up he tray icon.  The actual mouse moving code is only 6 lines.  Basically tells it, until someone closes the app, idle around for 30 seconds, then get the position of the mouse and move it right and left one pixel.  Then it loops and idles around fr 30 more seconds.

While 1
    Sleep(30000)
    $CurPos = MouseGetPos ( )
    MouseMove ( $CurPos[0] + 1, $CurPos[1] )
    MouseMove ( $CurPos[0] - 1, $CurPos[1] )
WEnd

Check out www.autoitscript.com if you are interested.  I do most my stuff in C#, but sometimes,  a simple script is all you need.

Cheers

+3
Login to vote
Orlando.Stevenson's picture

Looks like this approach should work well with Win 7 .  Would you mind sharing your 30 lines of full source code behind this.. perhaps include in your Winzip?     In our case, would be good if such a facility self-exited after so much time  - especially for conference rooms - and wouldn't take too much to enhance further.

Nice job!

    

+1
Login to vote
Mike.Langford's picture

Sure, here is the entire source code.  I will update the zip so it contains the uncompiled version as well.

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)

$AboutItem = TrayCreateItem("About")
TrayItemSetOnEvent(-1,"ReadList")
TrayCreateItem("")
$ExitItem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ReadList")

Func ReadList()
 $SelectedItem = TrayItemGetText(@TRAY_ID)
 If $SelectedItem="Exit" Then
  Exit
 ElseIf $SelectedItem="About" Then
  Call("About")
 EndIf
EndFunc

Func About()
 MsgBox(064,"No Sleep Utility","Prevents your computer from automatically locking or going to screen saver as it normally would." & @CRLF & "Copyright Mike Langford ©2009")
EndFunc

While 1
 Sleep(30000)
 $CurPos = MouseGetPos ( )
 MouseMove ( $CurPos[0] + 1, $CurPos[1] )
 MouseMove ( $CurPos[0] - 1, $CurPos[1] )
WEnd
+1
Login to vote
Mike.Langford's picture

FYI,
The ZIP now contains the Au3 file, which is just text based source code that Autoit can compile to an EXE.

+1
Login to vote
Sid Markolov's picture

Thanks for the code.  Looks pretty straight forward!

0
Login to vote
Tornadokat's picture

This causes my cursor to end up 2 pixels to the left every time.

0
Login to vote
heliwasp's picture

Actually the source code has a bug.

The mouse position has been stored in a local variable, so it should be moved back to that position. Instead, as a second move it is being set to initial position -1 (1 Pixel to the left):

 

MouseMove ( $CurPos[0] - 1, $CurPos[1] )

 

Replace that line with the following, and the mouse position shouldn't drift any longer:

 

MouseMove ( $CurPos[0], $CurPos[1] )

 

 

0
Login to vote
PatchRowcester's picture

You sir, are a genius! 

 

Thank you so much! 

0
Login to vote
Dilippatel's picture

This is genuine utility can we use in corporate?

0
Login to vote
k3nnyg's picture

Hmmmm.. not bad. This won't work for everything though. If you just want the computer not to lock this will work in most(not all) circumstances(Win7, Win8, UAC. Many more things to consider these days). Attached is a utility I wrote. Its in C# and uses pInvoke to get the exact timeouts for each profile and then adjusts the reset values accordingly. This will not move your mouse or type phantom characters like some do. This will also make you appear active on OCS, gchat, Lync, Outlook,etc. This works on ANY Windows version under any type ofdomain or individual security policy(GPOs). This utility is more meant to make you appear that you are actually at your terminal working even if you step away. Really it was written as a POC. The file ImWorkin.exe is in the root of the zip if you just want the pre-copmpiled exed. Otherwise the whole C# project is there for you too.

 

I dont condone slacking off but at times you may find a need for this utility. Use it wisely and dont abuse it too much because ultimatley it doesnt matter how your computer look if you arent actually producing your deliverables to your managment!

 

Enjoy

 

Source included in the zip.....Requires .NET 4 or above.

AttachmentSize
ImWorkin.zip 240.14 KB
0
Login to vote
bonjour madame's picture

FYI : Panda, Quick Heal and Clam AV detect a virus in NoSleep.exe: http://virusscan.jotti.org/en/scanresult/76c4d987b...

Nothing found in ImWorkin.exe

 

 

0
Login to vote
dimzay's picture

I just downloaded it.

It works fine, and I just love it.

You can make it better though.

Sometimes when I do drawing or move the mouse slowly it make the wonrg moves because your program does fake moves every 30 seconds.

First of all nobody makes screen savers on 30 seconds and it is not adjustable.

Should be like 5 minutes or adjustable.

Then you can make it more smart.

If the mouse makes the move (user moves it) then restart the timer.

Then it will work only when it is not in use.

 

Second thing you can do is you making it possinble to hide the icon from the bottom bar of the screen.

If my admin sees it he will punish me as it is a policy violation.

Please add the option to hide it.

Thanks

 

0
Login to vote
riva11's picture

About the second thing, you can hide icon on the system tray from the windows settings (Control Panel - Notification area icons)

0
Login to vote
k3nnyg's picture

Try the file I posted. It detects your timeouts and resets everything programatically just before they expire. It works in an RDP (remote) session also;)

 

Its safe. Source code is included.

0
Login to vote
dimzay's picture

@k3nnyg

ImWorkin did not work on my PC

 

0
Login to vote
JohnnyBMe's picture

My gateway antivirus says that ZIP contains a trojan. Seriously?

0
Login to vote
cwrich88's picture

most corporate users cant download an .exe file, how could i take your code and get it on my computer another way?

take the source and compile it? need options, thanks

0
Login to vote
donsurf's picture

Mike, Great useful idea.

I found this site looking for a way to put a time period around such a NoSleep function.

For example, during the hours of 9AM to 5PM, nosleep.exe would run and do it's thing.

Then outside the above time frame, (when no one should be working)  NoSleep.exe would

be idle or not running, to allow the system screensaver to take back control.

What do you think?  Is this a useful function, and it it possible to implement?

Either way, great thinking outside the box on your part.  Cheers, Don. 

 

ps.  I know i could terminate the exe before leaving, but sometimes humans forget.

      Or maybe, I could write a .bat file to start and stop Nosleep.exe when I log on 

      and logoff.   Maybe, I just answered my own question.  :)  Keep Thinking...!

 

 

0
Login to vote
interested_party's picture

I will have to try it.

0
Login to vote