byoda Posted June 30, 2010 Posted June 30, 2010 All, I have been trying to better understand why the following piece is not working correctly. It runs without error, but does not reboot system. Thanks... #include <process.au3> $ipaddress="192.168.50.1" run('shutdown -r -m \\'&$ipaddress&'')
AuToItItAlIaNlOv3R Posted June 30, 2010 Posted June 30, 2010 For reboot system use autoit function : Shutdown For reboot use this code : Shutdown(2) Remark : The shutdown code is a combination of the following values: 0 = Logoff 1 = Shutdown 2 = Reboot 4 = Force 8 = Power down 16= Force if hung 32= Standby 64= Hibernate Hi!
byoda Posted June 30, 2010 Author Posted June 30, 2010 Sounds good, but does it handle remote reboots? I am trying to reboot a remote machine.
Mat Posted June 30, 2010 Posted June 30, 2010 Running it like that will try to run a file called "shutdown.exe" in the working dir. You need to run cmd with it as a command line argument. run(@ComSpec & " /c shutdown -r -m \\" & $ipaddress) AutoIt Project Listing
byoda Posted June 30, 2010 Author Posted June 30, 2010 I tried this, but the command continues in a infinite loop and never reboots the remote system. Thanks.
Mat Posted June 30, 2010 Posted June 30, 2010 If you go into the windows run dialog and type (or paste) this: "cmd /c shutdown -r -m \\192.168.50.1" and run it then what happens? AutoIt Project Listing
byoda Posted July 1, 2010 Author Posted July 1, 2010 The remote machine shutsdown. When I run the script, it goes into infinite loop and machine does not shutdown.
Mat Posted July 1, 2010 Posted July 1, 2010 Kk... I don't know then. They *should* be the same in theory... What about: run(@ComSpec & " /c shutdown /r /m \\" & $ipaddress) Mat AutoIt Project Listing
byoda Posted July 1, 2010 Author Posted July 1, 2010 Same thing. Infinite loop. Just curious, were you able to run this on your side? Also, just as an isolation point, I do login to the remote machine, from the local before I run this script. Therefore, it should work.
Mat Posted July 1, 2010 Posted July 1, 2010 Same thing. Infinite loop. Just curious, were you able to run this on your side? Also, just as an isolation point, I do login to the remote machine, from the local before I run this script. Therefore, it should work. I had not tried, but I did and this was the result (after a bit of waiting) C:\Users\new user>shutdown -r -m \\192.168.50.1 192.168.50.1: The entered computer name is not valid or remote shutdown is not supported on the target computer. Check the name and then try again or contact your system administrator.(53) Probably got something to do with the fact 192.168.*.* is local isn't it? AutoIt Project Listing
byoda Posted July 1, 2010 Author Posted July 1, 2010 Not sure what you mean.... Here is my setup 1. 192.168.50.1 (Remote System) 2. 192.168.50.2 (Local System) From my local system, the first thing i do is go to Start->Run and type \\192.168.50.1 and it prompts me for username and password. I enter it and it logs me into the remote system. Then I run the script and it keep running over and over and over, without rebootin the remote system. Like we said, in theory it should work because the actual command works in the DOS prompt. Ive been all over this and cant figure it out.
Mat Posted July 1, 2010 Posted July 1, 2010 Well, I know that you have 4 IP addresses... AutoIt Project Listing
engjcowi Posted July 1, 2010 Posted July 1, 2010 hi my code would be slightly diffenerent. just substitute ipconfig for what u need Run(@ComSpec & " /c " & 'ipconfig.exe', "", @SW_HIDE) Drunken Frat-Boy Monkey Garbage
AdamUL Posted July 1, 2010 Posted July 1, 2010 @Mat Yes, 192.168.*.* is a private networking block. The reserved private networking blocks are The Internet Assigned Numbers Authority (IANA) has reserved the following three blocks of the IP address space for private internets: * 10.0.0.0 - 10.255.255.255 (10/8 prefix) * 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) * 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) As you found out, you cannot access these IPs outside of the private network. @byoda Does the account you are using to run the script on your local system have Admin rights on the remote PC? Here is a shutdown function that I wrote with error logging to a file. It uses the Windows Shutdown command. You need to see if the shutdown command is throwing any errors while running the script, and this function will log them. expandcollapse popup#include <File.au3> _RemoteShutdown("192.168.50.1", "r", 0, "", "Not Rebooted.") Func _RemoteShutdown($sComputer, $sArgument, $iTimeOut = 0, $sMessage = "", $sErrorLogMessage = Default, $sErrorLogFileName = Default) ;Uses #include <File.au3> ;Use #include <Constants.au3> if $STDOUT_CHILD is used somewhere else in the script. If $sErrorLogMessage = Default Then $iCreateLogFile = 0 Else $iCreateLogFile = 1 If Not IsString($sErrorLogMessage) Or $sErrorLogMessage = "" Then $sErrorLogMessage = "Shutdown not run." If $sErrorLogFileName = Default Then $sErrorLogFileName = StringTrimRight(@ScriptFullPath, 4) & " Errors.log" EndIf $sErrorLogMessage = $sComputer & " : " & $sErrorLogMessage $sShutdownOutput = "" $iNotExecuted = 0 If StringInStr($sArgument, "a") Then ;Abort $sArgument = "a" ElseIf StringInStr($sArgument, "r") Then ;Reboot $sArgument = "r" ElseIf StringInStr($sArgument, "s") Then ;Shutdown $sArgument = "s" Else $sShutdownOutput &= "Invalid shutdown type argument. " EndIf If Not IsInt($iTimeOut) Then $sShutdownOutput &= "Invalid Time Out argument. " ElseIf $iTimeOut < 0 Then $iTimeOut = 0 EndIf If $sShutdownOutput = "" Then Const $STDOUT_CHILD = 2 If $sArgument = "a" Then $iPIDShutdown = Run('shutdown -' & $sArgument & ' -m \\' & $sComputer, '', @SW_HIDE, $STDOUT_CHILD) Else If $sMessage = "" Then $iPIDShutdown = Run('shutdown -' & $sArgument & ' -f -t ' & $iTimeOut & ' -m \\' & $sComputer, '', @SW_HIDE, $STDOUT_CHILD) Else $iPIDShutdown = Run('shutdown -' & $sArgument & ' -f -t ' & $iTimeOut & ' -c "' & $sMessage & '" -m \\' & $sComputer, '', @SW_HIDE, $STDOUT_CHILD) EndIf EndIf ProcessWaitClose($iPIDShutdown) $sShutdownOutput = StringStripWS(StdoutRead($iPIDShutdown), 3) EndIf If $sShutdownOutput <> "" Then $iNotExecuted = 1 $sErrorMsg = " : " & $sShutdownOutput EndIf If $iNotExecuted Then If $iCreateLogFile Then _FileWriteLog($sErrorLogFileName, $sErrorLogMessage & $sErrorMsg) $sNamesOnlyErrorLogFileName = StringTrimRight($sErrorLogFileName, 4) & "-Names only.log" $iFoundComputerName = 0 If FileExists($sNamesOnlyErrorLogFileName) Then Local $aComputerNames _FileReadToArray($sNamesOnlyErrorLogFileName, $aComputerNames) For $iNameIndex = 1 To $aComputerNames[0] Step 1 If StringInStr($aComputerNames[$iNameIndex], $sComputer) Then $iFoundComputerName += 1 Next EndIf If Not $iFoundComputerName Then $hComputerNames = FileOpen($sNamesOnlyErrorLogFileName, 1) FileWriteLine($hComputerNames, $sComputer) FileClose($hComputerNames) EndIf EndIf Return SetError(1, 0, 0) Else Return 1 EndIf EndFunc ;==>_RemoteShutdown When you speak of an "infinite loop", is that part of your script, or is it just the remote PC not responding? Also if you notice in the code for my function, I use the -f to force processes to close. That could be one of your problems with the machine not rebooting. Adam
byoda Posted July 1, 2010 Author Posted July 1, 2010 All, I got it to work with the following. I just specified the shutdown location. run(@ComSpec & " /c c:\windows\system32\shutdown.exe r -m \\" & $ipaddress) Yes it has admin rights. When I speak of the infinite loop, when I run the script on the local machine, it would continously pop up DOS windows until I rebooted the machine. Seems to be working now. I would like to know wtf was going on with it:)
Mat Posted July 1, 2010 Posted July 1, 2010 All, I got it to work with the following. I just specified the shutdown location. run(@ComSpec & " /c c:\windows\system32\shutdown.exe r -m \\" & $ipaddress) Yes it has admin rights. When I speak of the infinite loop, when I run the script on the local machine, it would continously pop up DOS windows until I rebooted the machine. Seems to be working now. I would like to know wtf was going on with it:) Ah right... I never knew shutdown was a program This is right then? run("shutdown -r -m \\" & $ipaddress, @SystemDir) Good to see it sorted Mat AutoIt Project Listing
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now