Sign in to follow this  
Followers 0
Birdy1499

Reboot PC through script

5 posts in this topic

#1 ·  Posted (edited)

I am trying to reboot a pc after user inputs in how many minutes until the pc reboots, I know I am overlooking something and spent about 5 hours searching for an answer with no luck.
 
here is the code
 

#include <MsgBoxConstants.au3>
#RequireAdmin
Reboot()

Func Reboot()
    ; Asks the user to enter a time in minutes.
    Local $Time = InputBox("SET TIME FOR REBOOT", "IN MINUTES", "")
    $Min = 60
    $Reboot = $Time * $Min
    $command = ("C:\Windows\System32\shutdown.exe /r /t" $Reboot)
    Run ($command)
EndFunc

 
The rest of my code after this runs fine. Basically the program autoit runs can kill a remote session and a reboot brings it back. There is no way but guessing a good reboot time so a set time does not help. It does work great when I use
 
Run ("C:\Windows\System32\shutdown.exe /r /t 1800") I need to set the reboot time from user input.

Edited by Birdy1499

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Missing a space after /t ?

$command = ("C:\Windows\System32\shutdown.exe /r /t " & $Reboot)

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

i think your missing an & sign.

 

$command = ("c:location" & $Reboot) 

 

That should be the proper way. As it is, your running the command only (no time) because its not added to the string.

And you should label your stuff different. Input should be $mins and your multiplier should be seconds.

So it looks like

$Reboot = $Min * $Sec

Share this post


Link to post
Share on other sites

Thanks a bunch runs great, cleaned up the code as well,

#include <MsgBoxConstants.au3>
#RequireAdmin
Reboot()

Func Reboot()
    ; Asks the user to enter a time in minutes.
    Local $Sec = InputBox("SET TIME FOR REBOOT", "IN MINUTES", "")
    $Min = 60
    $Reboot = $Sec * $Min
    $command = ("C:\Windows\System32\shutdown.exe /r /t " & $Reboot)
    Run ($command)
EndFunc

Share this post


Link to post
Share on other sites

Looks great!

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