AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Shutdown Logoff Reboot Timer with Command Line..

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
shajul



Joined: 15 Sep 2006
Posts: 564

PostPosted: Tue Sep 08, 2009 7:45 pm    Post subject: Shutdown Logoff Reboot Timer with Command Line.. Reply with quote

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:


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 Wed Sep 09, 2009 2:46 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Muzzi



Joined: 15 Jun 2008
Posts: 111
Location: Sydney, Australia

PostPosted: Tue Sep 08, 2009 10:09 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
shajul



Joined: 15 Sep 2006
Posts: 564

PostPosted: Wed Sep 09, 2009 2:38 pm    Post subject: screenshot Reply with quote

lil improvements..

- screenshot added
- now reboot, sleep options as well..
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Muzzi



Joined: 15 Jun 2008
Posts: 111
Location: Sydney, Australia

PostPosted: Wed Sep 09, 2009 9:57 pm    Post subject: Reply with quote

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!! Mr. Green
Auto Delayed Shutdown GUI + Lock PC + Cancel + Hibernate + Restart + Switch User


Muzzi
Back to top
View user's profile Send private message
shajul



Joined: 15 Sep 2006
Posts: 564

PostPosted: Thu Sep 10, 2009 4:10 am    Post subject: Reply with quote

Hahaha..

Muzzi wrote:

Nice one!

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


Muzzi
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
DeWild1



Joined: 30 Apr 2006
Posts: 358
Location: Shigle Springs

PostPosted: Sun Sep 13, 2009 1:09 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
shajul



Joined: 15 Sep 2006
Posts: 564

PostPosted: Sun Sep 13, 2009 3:06 am    Post subject: Reply with quote

Why not use singleinstance ignore?
Also, why not use a timer to check the time?
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
DeWild1



Joined: 30 Apr 2006
Posts: 358
Location: Shigle Springs

PostPosted: Sun Sep 13, 2009 11:28 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
ahkiot0



Joined: 31 May 2008
Posts: 36

PostPosted: Sat Nov 21, 2009 9:03 pm    Post subject: Reply with quote

forum engine by regret no "thanks" button and "rate topic" thanks! shajul
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group