AutoHotkey Community

It is currently May 26th, 2012, 10:38 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: September 8th, 2009, 8:45 pm 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
This script is

1 - manual a shutdown timer
2 - with command line parameters
3 - with shutdown in 11 minutes if no user interaction.

I use this script to auto-shutdown at the end of my download queue's, in association with any scheduler etc..

The time and code can also be input manually, or the shutdown code can be omitted (defaults to 1+4=5).

The GUI idea was inspired by Muzzi in this thread. (The GUI i was using was a tiny one, but i liked the full-screen idea)

Pls feel free to modify according to your needs..

Screenshot:
Image

Code:
/*  Shutdown Timer v1.1
              by Dr. Shajul

Shutdown after a specified interval!
Command line parameters are also accepted, in minutes..
  eg Shutdown_timer.exe 10 5
  .. will force shutdown (code 5) in 10 minutes
*/


;;********** Settings, Variable Declarations **********
#SingleInstance Force
#NoEnv
OnExit, quit

programName = Shutdown Timer
programVersion = 1.2
programFullName = %programName% v%programVersion%
programAuthor = Shajul


;;********** Auto-Execute Section **********
GoSub, trayMenu    ; construct tray menu : OPTIONAL
scode=5
if 0>0
   {
   tvar = %1%
   scode = %2%
   if not scode
      scode=5
   }
else
   {
   InputBox, tvar, Shutdown computer in.. (minutes),Format`:`"<Time in minutes> <[shutdown code]>`"`nEg. `"10 5`",,400,150,,,,60,10 5
   ; if cancel was pressed, return
   if errorlevel=1
     ExitApp
   IfInString, tvar, %A_Space%
      {
      StringSplit,tvar,tvar,%A_Space%
      tvar:=tvar1
      scode:=tvar2
      }
   }

if tvar is number
  {
   shuttime := tvar
   Settimer,Shuttime,60000
   Gui, +AlwaysOnTop -Disabled -SysMenu +Owner -Caption -ToolWindow ; stay on top to prevent access whilst in pre shutdown mode.
   Gui, Font, s24 cFFFFFF
   my_x := (A_ScreenWidth/2)-100
   my_y := (A_ScreenHeight/2)-100
   Gui, Add, Button, x%my_x% y%my_y% h60 w200 gQuit Section, Cancel
   Gui, Add, Button, xs-250  y%my_y% h60 w200 gHibernate, Hibernate
   Gui, Add, Button, xs+250  y%my_y% h60 w200 gShutdown, Shutdown
   my2_y := my_y + 90
   Gui, Add, Button,  x%my_x% y%my2_y% h60 w200 gLogOff, Logoff
   Gui, Add, Button, xs-250  y%my2_y% h60 w200 gSuspend, Suspend
   Gui, Add, Button, xs+250  y%my2_y% h60 w200 gRestart, Reboot
   my3_y := my_y + 180
   Gui, Add, Checkbox,  x%my_x% y%my3_y% h60 w200 vforce center, Force?
   Gui, Font, s40 cFFFFFF
   my4_y := my_y - 100
   Gui, Add, Text, xs-200 y%my4_y% w600 vMyText, %A_Space%Shutdown in %Shuttime% minutes!
   Gui, Color, 000000                                   
   Gui, Show, x0 y0 h%A_ScreenHeight% w%A_ScreenWidth%, ScreenMask
   WinSet, Transparent, 200, ScreenMask
   Gosub, Shuttime
  }
else
   MsgBox, 48, Invalid Data, Please enter a valid 3-digit number!,
return



;;********** Subroutines **********
Shuttime:
shuttime--
GuiControl,, MyText, %A_Space%Shutdown in %shuttime% minutes!
if shuttime <= 0
  {
   Shutdown,%scode%
   Settimer,Shuttime,off
  }
Return

Shutdown:
Gui, Submit, NoHide
if force
   Shutdown,5
else
   Shutdown,1
return

Hibernate:
Gui, Submit, NoHide
if force
  DllCall("PowrProf\SetSuspendState", "int", 1, "int", 1, "int", 0)
else
  DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
Return

Suspend:
Gui, Submit, NoHide
if force
  DllCall("PowrProf\SetSuspendState", "int", 0, "int", 1, "int", 0)
else
  DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
Return

Restart:
Gui, Submit, NoHide
if force
   Shutdown,6
else
   Shutdown,2
return

Logoff:
Gui, Submit, NoHide
if force
   Shutdown,4
else
   Shutdown,0
return

trayMenu:
   Menu, Tray, Tip, %programFullName%
   Menu, Tray, NoStandard
   Menu, Tray, Add, &About, about
   Menu, Tray, Add
   Menu, Tray, Add, &Quit, quit
Return

about:
   MsgBox, 64, %programFullName%,
   ( LTrim
      %programFullName%
      %A_Space%by %programAuthor%

      Shutdown after a specified interval!
   )
Return

Quit:
ExitApp
Return


Last edited by shajul on September 9th, 2009, 3:46 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2009, 11:09 pm 
Offline

Joined: June 15th, 2008, 8:01 am
Posts: 111
Location: Sydney, Australia
I am happpy that someone has taken advantage of my script, very nice work Shajul.... if it suits your needs good for you!

Thank you.

Muzzi


Report this post
Top
 Profile  
Reply with quote  
 Post subject: screenshot
PostPosted: September 9th, 2009, 3:38 pm 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
lil improvements..

- screenshot added
- now reboot, sleep options as well..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2009, 10:57 pm 
Offline

Joined: June 15th, 2008, 8:01 am
Posts: 111
Location: Sydney, Australia
Quote:
lil improvements..

- screenshot added
- now reboot, sleep options as well..


Nice one!

We both sound like a couple of kids..... now I've added a Switch User!! :mrgreen:
Auto Delayed Shutdown GUI + Lock PC + Cancel + Hibernate + Restart + Switch User


Muzzi


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2009, 5:10 am 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
Hahaha..

Muzzi wrote:
Nice one!

We both sound like a couple of kids..... now I've added a Switch User!! :mrgreen:
Auto Delayed Shutdown GUI + Lock PC + Cancel + Hibernate + Restart + Switch User


Muzzi


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2009, 2:09 am 
Offline

Joined: April 30th, 2006, 6:23 pm
Posts: 358
Location: Shigle Springs
I tried making a shutdown program and I made it not show any gui or message boxes, then I installed it as a service.
It does not work.

Any body know of any DLL calls I could try?
Code:
               ; lParam will be a copy of 1st parameter
#SingleInstance, OFF          ; Allow many instances, instances are handled by the script
#NoTrayIcon                   ; Will be shown later if it is the 1st instance of script
#Persistent                 
DetectHiddenWindows, On       
SetWorkingDir, %A_ScriptDir%  ; Simplifies path handling when script is started with .LNK
A_SFP := A_ScriptFullpath   
lParam = %1%   
WinGet, Instance, List, %A_ScriptFullPath%        ; "Instance" contains No. of Instances
IfGreater,Instance,1, IfEqual,lParam,, ExitApp    ; Force SingleInstance when first

loop,
{
sleep, 3000000
if A_Hour in 6
Shutdown, 6
if A_Hour in 10
Shutdown, 6
if A_Hour in 19
Shutdown, 6
}

_________________
CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2009, 4:06 am 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
Why not use singleinstance ignore?
Also, why not use a timer to check the time?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2009, 12:28 am 
Offline

Joined: April 30th, 2006, 6:23 pm
Posts: 358
Location: Shigle Springs
shajul wrote:
Why not use singleinstance ignore?
Also, why not use a timer to check the time?


Singleinstance, ignore does not always seem to work for me. Sometimes i can get two of the same comiled scripts running at the same time.

Not sure about a timer to check time, but I did it that way just to make it reboot one time durring those hours.
(it only takes about 1 min to reboot)

You see, GUIs and Msgbox, do not work as a service, but for some reason sutdown does not work too as a service.
No biggy, I wil just put it in startup and use sysinternals autologon.exe

_________________
CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 10:03 pm 
Offline

Joined: May 31st, 2008, 3:22 pm
Posts: 47
forum engine by regret no "thanks" button and "rate topic" thanks! shajul


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: jrav and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group