Jump to content

Remote Server Shutdown


Recommended Posts

I'm a newbe to Autoit, so forgive my ignorance I have looked through almost every topic that has remote shutdown in it but still seem unable to make the script work in either a domain or workgroup enviroment.

I have tested this in Windows 7 / XP Pro SP2 Worgroup and Domain no go in all error the same.

The Problem is I require to shut down several server 10+ in a specific sequence and on/in a windows domain.

So this is what I have done so far, please see attached script, I cannot find why its not working even when i try the command without any verables all i get is a pause and a blank screen with no error, I check the servers thay are still up..

option I have tried with no sucess are:

('shutdown -s -f -m server1 -t 20 -c "Datensicherung von Büro"',"",@SW_HIDE)

verious WMI options but all give the same error object type needs to be set or simlair.

Func shutdown_servers()

For $x = 0 To 2 Step 1

$hostname = $server[$x]

MsgBox(64, "remote shutting down:", $hostname, 1)

Run (@ComSpec & " /c " & "shutdown.exe -r -m \\" & $hostname & " -t 120 -f", @SystemDir, @SW_HIDE)

Next

EndFunc ;==>shutdown_servers

and last but not least, a very simplistic approch

RunWait('shutdown -r -f -m \\scalaserver -t 20 -c "shuttingdown scala server"',"",@SW_HIDE)

RunWait('shutdown -r -f -m \\serverbkuphq -t 20 -c "shuttingdown backup server"',"",@SW_HIDE)

RunWait('shutdown -r -f -m \\carvm1 -t 20 -c "shuttingdown VM1 server"',"",@SW_HIDE)

RunWait('shutdown -r -f -m \\intranetserver -t 20 -c "shuttingdown intranet server"',"",@SW_HIDE)

RunWait('shutdown -r -f -m \\server1 -t 20 -c "shuttingdown Primary server"',"",@SW_HIDE)

Which also did not work...

I know i am doing somthingwrong but for the life of me after 3 days of searching the forums and trial but mostly error I have resorted to pleading for help.

This seemed like a simple issue it can be done in a batch file etc. but does not seem to convert over to autoit very well.

Please advise this seems a common issues that I have found no solution so far.

caressdv.3.au3

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Link to comment
Share on other sites

  • Developers

I normally use the PSTOOLS for that in this case PSSHUTDOWN.

This should work fine in an AD environment.

Jos ;)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I normally use the PSTOOLS for that in this case PSSHUTDOWN.

This should work fine in an AD environment.

Jos ;)

Thanks but does not really help in this case, as i am still none the wiser i seem to have two issues:

Func shutdown_servers()

For $x = 0 To 2 Step 1

$hostname = $server[$x]

MsgBox(64, "remote shutting down:", $hostname, 1)

RunAs("administrator", "cfu", "password",2 , @ComSpec & " /c " & "shutdown.exe -r -m \\" & $hostname & " -t 120 -f", @SystemDir)

Next

EndFunc ;==>shutdown_servers

1) the above variable $hostname name seems not to be getting parsed correctly to the RunAs command in this example but does to the MsgBox? I'm i doing something wrong there.

2) even when i substitute the RunAs line for RunWait('shutdown -r -f -m \\server1 -t 20 -c "shutting down Primary server"',"",@SW_HIDE) it still does not work? again what am i doing wrong.. or is this a bug?

Even if i was to use the PSSHURDOWN tools you have suggested I would still need to get item one sorted out to make it useful, I have run this through the debug console in SciTE but seems to be no errors it can find.

Hope this sheds a little more light on the subject.

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Link to comment
Share on other sites

  • Developers

Have you tried the command from the CMD prompt and was that working?

If so, what was the exact command you typed.

When you want to know the exact command line ran than this could show that when ran from SciTE:

Func shutdown_servers()
    For $x = 0 To 2 Step 1
        $hostname = $server[$x]
        RunAsWait("administrator", "cfu", "password", 2, @ComSpec & " /c shutdown.exe -r -m \\" & $hostname & " -t 120 -f", @SystemDir)
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c shutdown.exe -r -m \\" & $hostname & " -t 120 -f" = ' & @ComSpec & " /c shutdown.exe -r -m \\" & $hostname & " -t 120 -f" & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    Next
EndFunc   ;==>shutdown_servers

You could also try running it with the /K switch so the CMD window stays open and you could see any errors displayed:

RunAsWait("administrator", "cfu", "password", 2, @ComSpec & " /k shutdown.exe -r -m \\" & $hostname & " -t 120 -f", @SystemDir)

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Have you tried the command from the CMD prompt and was that working?

If so, what was the exact command you typed.

When you want to know the exact command line ran than this could show that when ran from SciTE:

Func shutdown_servers()
    For $x = 0 To 2 Step 1
        $hostname = $server[$x]
        RunAsWait("administrator", "cfu", "password", 2, @ComSpec & " /c shutdown.exe -r -m \\" & $hostname & " -t 120 -f", @SystemDir)
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c shutdown.exe -r -m \\" & $hostname & " -t 120 -f" = ' & @ComSpec & " /c shutdown.exe -r -m \\" & $hostname & " -t 120 -f" & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    Next
EndFunc   ;==>shutdown_servers

You could also try running it with the /K switch so the CMD window stays open and you could see any errors displayed:

RunAsWait("administrator", "cfu", "password", 2, @ComSpec & " /k shutdown.exe -r -m \\" & $hostname & " -t 120 -f", @SystemDir)

Jos

OK thanks you really pointed me in the right direction, the script I have attached works fine now, all I have to do is tidy it up and add a few refinements..

Found out the main issue was permissions I had to add the user locally with the same username and password that I was using remotely to access the system holding administrative rights on the remote system.

Found this out by reading this article http://www.digitalspy.co.uk/forums/showthread.php?t=300058;

I have also attached the script working and verified for anyone else that may be intrested.

Just as a side note pstools did not work but that is to be expeced as in the end it was a permission issue, your idea of putting a /k switch instead of a /c in the command line of the RunAs was awsome, thanks.

This is my first autoit script and really pleased there seems to be a scripting langauge that I can use in some fasion arround.

caressdv.3.au3

[topic='115020'] AD Domain Logon Script[/topic]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...