Sign in to follow this  
Followers 0
Pumagaju

Help with reboot and script delay

7 posts in this topic

I have a script to run gpudate /force. After completion I want them to reboot without forcing them. However, if after two hours they havent rebooted I want to do a force shutdown. Anyone know of a function that will allow for a "click now" to reboot and/or then wait routine?

Here is my script so far:

RunWait(@ComSpec & " /c " & "gpupdate /force", "", @SW_HIDE)

Sleep(200000);two hours

MsgBox(64, "SIC - Complete", "You are now being rebooted.")

Shutdown(6) ;Force a reboot

Thanks,

Share this post


Link to post
Share on other sites



Easiest way would be to make a gui. then user _timer_init and covert out 2 hours to milliseconds.


Giggity

Share this post


Link to post
Share on other sites

Easiest way would be to make a gui. then user _timer_init and covert out 2 hours to milliseconds.

Can anyone point me to some resources for creating such a gui?

Thanks,

Share this post


Link to post
Share on other sites

Easiest way would be to make a gui. then user _timer_init and covert out 2 hours to milliseconds.

So I have created a basic gui to meet my needs. However, I have come across one small glitch. If the user chooses the "wait" option then the gui box doesnt go away. Is there any way to clear that so that while the script continues to run?

Here is my code:

#include <GUIConstantsEx.au3>

GUICreate("Action Required", 300, 100)
GUICtrlCreateLabel("Please choose which reboot option works best for you:", 30, 10)
$okbutton = GUICtrlCreateButton("Reboot Now", 50, 50, 70)
$ok2button = GUICtrlCreateButton("Reboot in 2 Hours", 150, 50, 100)
GUISetState(@SW_SHOW)

While 1
  $msg = GUIGetMsg(1)

  Select
    Case $msg = $okbutton
      Shutdown(6)  ;Force a reboot

    Case $msg = $ok2button
      MsgBox(0, "Alert", "You're machine will reboot two hours from now!")
      ExitLoop
  EndSelect
WEnd

Sleep(200000) ;two hours

Shutdown(6)  ;Force a reboot

Thanks,

Share this post


Link to post
Share on other sites

If you're working in windows, you could just use the command-line call 'shutdown' via a shellexecute

Here's the code necessary in AutoIt:

ShellExecute( "CMD.exe", "/C shutdown -r -t 7200" )

This will launch a shutdown dialog with a timeout of 7200 ( this is seconds ). If you want to see how it works outside of AutoIt, then in a command window type: shutdown -r -t 01. The computer will restart after 1 second.

This will allow you to finish execution on the original script and then windows will take care of the reboot.

Alternately, If you want to handle the reboot inside AutoIt, then you may want to use TimerInit() and TimerDiff().

Share this post


Link to post
Share on other sites

@Pumagaju

$GUI = GuiCreate(...)
GuiSetState(@SW_HIDE, $GUI)

Cheers, FireFox


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Awesome! Thanks for the help. Those ideas work great!

I appreciate your help.

Gary

Share this post


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
Sign in to follow this  
Followers 0