Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Shutdown Logoff Reboot Timer with Command Line..


  • Please log in to reply
8 replies to this topic
shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
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:
Posted Image

/*  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


Muzzi
  • Members
  • 111 posts
  • Last active: Dec 15 2013 03:54 AM
  • Joined: 15 Jun 2008
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

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
lil improvements..

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

Muzzi
  • Members
  • 111 posts
  • Last active: Dec 15 2013 03:54 AM
  • Joined: 15 Jun 2008

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

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
Hahaha..

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



DeWild1
  • Members
  • 369 posts
  • Last active: Feb 28 2014 08:15 PM
  • Joined: 30 Apr 2006
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?
; 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
}


shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
Why not use singleinstance ignore?
Also, why not use a timer to check the time?

DeWild1
  • Members
  • 369 posts
  • Last active: Feb 28 2014 08:15 PM
  • Joined: 30 Apr 2006

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

ahkiot0
  • Members
  • 51 posts
  • Last active: Mar 11 2015 12:45 AM
  • Joined: 31 May 2008
forum engine by regret no "thanks" button and "rate topic" thanks! shajul