Jump to content

Recommended Posts

So I was working on something this morning that can be very useful seeing as we all have users who dont know how to shutdown, particularly lawyers and insurance guys.

Originally written as per request from a family member to stop annoying kids from never shutting down the thing.

Figured id share it with the world.

#include <Timers.au3>
#include <Date.au3>
#include <File.au3>

$Timeout = <Desired time (ms!)>
$Directory = "C:ShutdownLog"
$File = "C:ShutdownLogLog.txt"
$uFile = @UserProfileDir & "SDLog.txt"
$LFile = @UserProfileDir & "LogonLog.txt"
$FileHandle = FileOpen($File, 1)
$uFileHandle = FileOpen($uFile, 1)
$LFileHandle = FileOpen($LFile, 1)
$SDCount = _FileCountLines($uFileHandle)
$LCount = _FileCountLines ($LFileHandle)

If FileExists($File) = 0 Then
   FileWriteLine($uFileHandle, "This File Contains:" & @LF & "A Log of all unwanted shutdowns on this user" & @LF)
   FileWriteLine($LFileHandle, "Logons for this User:" & @LF)

FileWriteLine ($LFileHandle, "Logon at: " & _NowCalc & @LF)
FileClose ($LFile)

$Math = $SDCount / $LCount
If $Math >= 0.5 Then
   MsgBox( 0, "Hey You!", "You REALLY need to learn to Shutdown before you just walk away!")

While $n=1
   $TimeIdle = _Timer_GetIdleTime()
   If $TimeIdle >= $Timeout Then
   FileWriteLine ($FileHandle, "Shutdown at: " & _NowCalc() & " Logged on user was: " & @UserName & @LF)
   FileWriteLine ($uFileHandle, "Shutdown at: " & _NowCalc() & " while you were logged on" & @LF)
   Shutdown (5)

Just replace <DesiredTime> with your idle time in ms, put in your startup folders and youre good to go!

XP: C:Documents and SettingsAll UsersStart MenuProgramsStartup

7: C:ProgramDataMicrosoftWindowsStart MenuProgramsStartup (Its a hidden system folder!)

Thanks to


for helping me out with this one.

Note: as seen in DO NOT run the following line in a script:

Run (@ComSpec & " /c " & "Shutdown.exe -s -t 01", "", @SW_HIDE)

Not sure why, but the comptuer freaks out and then you when it actually does shut down you get to wait 20 minutes and then hold the power button down to shut it down and then when your computer doesnt come back alive you have to pull out the battery. (Tested twice)


Edit: changed Shutdown(13) to Shutdown(5) so as to remove the powerdown function. thanks to user 69255

Edited by RedneckTech
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...