Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shutdonw multicomputer remotly 3

Status
Not open for further replies.

mosaur

IS-IT--Management
Oct 19, 2007
38
JO
how to write script to shutdown computers remotly using this command
shutdown /r /m \\computername

I use one domain controller and all pc's are xp.
 
shutdown /r /m \\computername /t seconds /f {force shutdown, no warning} or shutdown /i or

Try this VBScipt. Copy and paste the below text in to notepad. then save it with the extension .vbs. Then when you double click it, it should give you an input box. What ever IP or PC name you enter there will be shut down!:

Sub RebootComputer( strServer )
Set objOSSet = GetObject("winmgmts:{(RemoteShutdown)}//" & strServer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")

For each objOS in objOSSet
objOS.Reboot()
Next
End Sub


' *************************************************************
' Main
' **************************************************************
Dim strComputer
Do
strComputer = inputbox( "Please enter the name of the computer you want to reboot", "Input" )
Loop until strComputer <> ""

RebootComputer( strComputer )

WScript.Echo( "Computer " & strComputer & " rebooted" )
 
You can also purchase for a small amount a product called Visual Cron at that will do this for you. It works perfect. You do not have to be a programmer to use it. We reboot all of our servers nightly(100+) with one Visual Cron Job.
 
I posted a script to do this a while back. Check
I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Dear bracadar .
thanks for your help,
but I have about 100 pc and I know the name of all these pc's . so I can put it in text file and let the script to read from this script .
so how to do it .
 
Mosaur, read the thread that markdmac points you to. It does exactly as you want. If you don't want to go to the link, here is the code:

Code:
'==========================================================================
'
' NAME: RebootWSfromList.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 7/6/2004
'
' COMMENT: <comment>
'
'==========================================================================

On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer In RemotePC
    Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & strComputer).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
        for each OpSys in OpSysSet
            OpSys.Reboot()
         next
Next


Once again mark, good stuff.
 
Just name the file WSLIST.TXT and execute the script in the same directory as the text file.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Have you tried using PSEXEC?
(
This will allow you to run the shutdown command (or any other command that you would normally run locally) remotely to a server or even a list of servers.

with PSEXEC installed on your DC for example and a text file of all the pc's there as well (computers.txt), you would go to a command prompt on the DC and type the following:

c:\psexec> PSEXEC @computers.txt shutdown -r -f -t 3 (or whatever options you need)

Remember this command is run locally on the remote machine so you do not use the shutdown options like it is remote (\\computername)

Give it a try, it works great, i use it for a lot of different things including rebooting batches of servers at once, applying patches, whatever you can think of (almost).

Good Luck!
-Steve
 
Can you be more specific?

Do you get any error messages? Did you create the WSLIST.TXT file? Are you logged on as an admin with rights to the remote machines? Do you have rights to reboot? Are you blocking remote WMI execution with the Windows Firewall?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
I will try PSEXEC and will tell you .
 
Interestingly I'm needing to ensure all of my systems are shut down due to maintenance on our power system.

Mark - Your script works perfect to reboot the systems...I need (and the OP as well which may indicate why he said it didn't work) to shutdown the systems in wslist.txt, not reboot them, which is what your script does. I'm just getting into the scripting deal so not sure which line to change to to a shutdown instead of a reboot.

I'm Certifiable, not cert-ified.
It just means my answers are from experience, not a book.
 
Duh...changed "ReBoot()" to "ShutDown()" and it works perfect.

Thanks Mark!

I'm Certifiable, not cert-ified.
It just means my answers are from experience, not a book.
 
Glad you figured it out Dave.

Here is a version that will prompt for reboot or shutdown.

Code:
'==========================================================================
'
' NAME: RebootOrShutDownWSfromList.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 7/6/2004
'
' COMMENT: This script and many more can be found in  
'          The Spider's Parlor's Admin Script Pack
'
' MODIFICATIONS: 12/18/2007 - Prompt for reboot or shutdown
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
'==========================================================================

On Error Resume Next

'Prompt for mode
Mode = InputBox("Do you wnat to reboot or shutdown the machines in the list?" _ 
				& vbCrLf & "1 = Reboot" & vbCrLf & "2 = Shutdown","Reboot or shutdown?")


'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer In RemotePC
    Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & strComputer).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
        For Each OpSys in OpSysSet
			Select Case UCase(Mode)
				Case "1","REBOOT"
					OpSys.Reboot()
				Case "2","SHUTDOWN"
					OpSys.Shutdown()
				Case Else
					MsgBox "Invalid Mode Entered, Quiting Script",vbExclamation,"Invalid Mode"
					WScript.Quit
         	End Select
         Next
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks Mark, I can use that.


"We must fall back upon the old axiom that when all other contingencies fail, whatever remains, however improbable, must be the truth." - Sherlock Holmes

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top