Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In my company staff have to check in after retch to company and check out before leave company on a internal site, sometimes I forget it totally...it's awful. Now i want a program which shows a prompt window when lock/logoff/shutdown, in this way i won't forget any more.

Indeed I develop a program (some words and two buttons), and configure this program started when lock/logoff/shutdown in group policy, here is the question:

How can I prevent my windows 7 shutdown/logoff/lock?

It means I click the button "Yes, I want" my pc still running and chrome or something showed up, if i click the button "No, thanks", my pc will shutdown/logoff/lock.

share|improve this question
4  
Sorry, but this won't help you, your body will soon learn how to press the yes-button automatically for you and you will not remember to read the text in the popup. –  Albin Sunnanbo Nov 15 '10 at 8:52
    
Post-it note on the screen? Sometimes the easiest solutions are the best ones. Also, @Albin is right. –  falstro Nov 15 '10 at 8:53
2  
possible duplicate of Intercept Windows Vista shutdown event in C# –  Albin Sunnanbo Nov 15 '10 at 8:55
add comment

migrated from stackoverflow.com Nov 15 '10 at 23:03

This question came from our site for professional and enthusiast programmers.

2 Answers

If you've got a program that does the "yes/no" side of things then you could set it to run or, as appropriate, kill this program:

http://www.softpedia.com/get/Others/Miscellaneous/Caffeine.shtml

Caffeine is a program that keeps your computer from going to screensaver or locking, but if you're working in a company environment you wouldn't want it to always be running as it would stop your machine from locking when you go home which may be bad if anyone else has access to it.

What I'd do then is write a simple little batch script and set up a task in the Windows Scheduler to run it every half an hour or so:

tasklist /FI "IMAGENAME eq caffeine.exe" 2>NUL | find /I /N "caffeine.exe">NUL
if "%ERRORLEVEL%"=="1" start caffeine.exe

echo "press CTRL-C within 60 seconds to keep using this machine"
timeout /T 60
taskkill /IM caffeine.exe
taskkill /T /IM caffeine.exe

If you press Control-C (and accept the "terminate batch" prompt) then your machine will stay awake, if you don't accept it then caffeine will be killed and your machine will lock up or do whatever it is meant to do. For some reason on my machine I have to either try to kill it both ways or try to kill it twice to get it to go away...

share|improve this answer
    
Won't caffeine.exe continue to run, and without termination it will never get to the echo/pause? Also, pause 60 doesn't work -- Windows does not have such an argument for pause, one of the only real viable ways to natively do a sleep in consumer editions of Windows is to do something like ping 127.0.0.1 -n 2 > NUL. –  Matthieu Cartier Dec 22 '10 at 12:54
    
Fixed it :) The Timeout command kinda works, you still get the "terminate batch" prompt but it is inline with the output of the timeout command. I've tried the script and it works (with quirks and all) on my Vista machine at least... –  Mokubai Dec 22 '10 at 13:04
add comment

It's better you create a windows service that run at startup and grant a right privileges. For intercept windows shutdown you could read this post

share|improve this answer
    
i am going to see that question. it seems like the questions will be solved soon, thx ^-^ –  Anonymous Nov 15 '10 at 9:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.