You are on page 1of 4

private sub btnboot_click(byval sender as system.

object, _
> byval e as system.eventargs) handles btnboot.click
> 'get name of computer to reboot
> '(list on the web page named lstmemberlist contains the names)
> dim strcomputer as string = lstmemberlist.selecteditem.text
> 'wmi objects
> dim objmanscope as system.management.managementscope
> dim objquery as system.management.objectquery
> dim objsearcher as managementobjectsearcher
> dim colquerycollection as managementobjectcollection
> dim outparams as managementbaseobject
> dim colinstances as collection
> dim objinstance
> dim strwqlquery as string
> dim intresult as integer
> 'build wql string
> strwqlquery = "select * from win32_operatingsystem " & _
> "where primary = ""true"""
> 'connect to wmi on remote computer
> objmanscope = new system.management.managementscope("\\" & _
> strcomputer & "\root\cimv2")
> objquery = new system.management.objectquery(strwqlquery)
> objsearcher = new managementobjectsearcher(objmanscope, objquery)
> colquerycollection = objsearcher.get
> 'reboot remote computer
> for each objinstance in colquerycollection
> 'intresult = objinstance.win32shutdown(6) '6 = forcedreboot
> outparams = objinstance.invokemethod("reboot", "", "")
> next
> end sub
>
> -----------------------------------------------------

remote server shutdown options - david


27-dec-07 01:14:31

i've been using apc's powerchute software (with their ups's) to handle
graceful shutdown of my servers in case of power outage. the software
supports up to 5 servers and i just added server number 6.

i don't think my environment is really big enough to justify buying their


network based solution and so i'm thinking about simply using a script
(simple batch, wsh, whatever) to shutdown this 6th server in case of power
failure. the existing apc software allows you to execute a file when power
goes out so i assume i can do this:

servera has ups attached via serial cable, power goes out, servera executes
script that shuts down serverb and serverc (which also have their power
connected to the same ups as servera, obviously, but no serial (data)
connection), then apc software continues to shutdown servera itself.

1) any issues with this?


2) what are some of my options to perform the remote shutdown?
3) looking ahead, any config changes needed on servers to allow them to be
shutdown remotely (on dc's for example)

button
remote server shutdown options - hal rottenberg
27-dec-07 08:11:28

from xp help (similar command exists on 2000, vista and 2003 have an
enhanced version with additional options if i recall correctly):

shutdownallows you to shut down or restart a local or remote computer.


used without parameters, shutdown will logoff the current user.

syntax
shutdown [{-l|-s|-r|-a}] [-f] [-m [\\computername]] [-t xx] [-c

parameters
-l
logs off the current user, this is also the defualt. -m computername
takes precedence.
-s
shuts down the local computer.
-r
reboots after shutdown.
-a
aborts shutdown. ignores other parameters, except -l and computername.
you can only use -a during the time-out period.
-f
forces running applications to close.
-m [\\computername]
specifies the computer that you want to shut down.
-t xx
sets the timer for system shutdown in xx seconds. the default is 20
seconds.
-c "message"
specifies a message to be displayed in the message area of the system
shutdown window. you can use a maximum of 127 characters. you must
enclose the message in quotation marks.
-d [u][p]:xx:yy
lists the reason code for the shutdown. the following table lists the
different values. value description
u indicates a user code.
p indicates a planned shutdown code.
xx specifies the major reason code (0-255).
yy specifies the minor reason code (0-65536).

/?
displays help at the command prompt.
remarks
if you indicate a major and minor reason code, you must first define
these reason codes on each computer for which you plan to use the
particular reason. if the reason codes are not defined on the target
computer, event viewer cannot log the correct reason text.
examples
to shut down \\myserver in 60 seconds, force running applications to
close, restart the computer after shutdown, indicate a user code,
indicate that the shutdown is planned, log major reason code 125, and
log minor reason code 1, type:
shutdown -r -f -m \\myserver -t 60 -d up:125:1

formatting legend
format meaning
italic information that the user must supply
bold elements that the user must type exactly as shown
ellipsis (...) parameter that can be repeated several times in a command
line
between brackets ([]) optional items
between braces ({}); choices separated by pipe (|). example: {even|odd}
set of choices from which the user must choose only one
courier font code or program output

--
hal rottenberg <hal@halr9000.com>
author, techprosaic (http://halr9000.com)
webmaster, psi (http://psi-im.org)
co-host, powerscripting podcast (http://powerscripting.net)

button

remote server shutdown options - al dunbar


27-dec-07 10:07:50

any argument that, technically, you should upgrade the apc software to
whatever it needs to be to handle more than five servers is, quite frankly,
a bit silly. if the software itself gives you an option to invoke some
external process through a program or script, then using that for whatever
purpose presents itself is something that the company has already allowed.

beyond that obvious possible issue is apc's liability. if they have a


guarantee that requires them to fix/replace any equipment it fails to shut
down, that guarantee will probably not extend to any servers protected
indirectly by a script you might implement.

not specifically. to follow hal's advice, you will need to ensure that the
account running your remote shutdown script has the privileges required to
remotely shutdown the servers.

/al

button

remote server shutdown options - david


28-dec-07 08:29:31

thanks al.

button

remote server shutdown options - david


28-dec-07 08:29:42

thanks hal.
button

remote server shutdown options - ir


01-feb-08 05:29:27

hello david,

i have been using the following command line from a batch file.

shutdown /r /f /t 60 /d p:2:4

this works great on server 2k3. i have also used this on older servers. i
just copy the shutdown.exe to the system32 file, then i create a scheduled
task to run the batch file. i have a few systems that require a reboot almost
everyday due to memory leaks in a few legacy apps.

the /t 60 gives you a 60 second delay. i have it there in the event i need
to do a shutdown -a.

the "p:2:4" are codes for srvr 2k3 after the reboot. i found the referance
to this on the internet of course. thank you one and all.

button

You might also like