subroutine in vbscript to reboot: Sub RebootMachine(compName) Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate,(Security,Shutdown)} !\\" & compName & "\root\cimv2") Set OS_Set = wmi.Get("Win32_OperatingSystem") For Each os in OS_Set.Instances_() '*** Force Reboot *** ret = os.Win32Shutdown(6) Next End Sub
-----Original Message----- From: Ben Scott [mailto:mailvor...@gmail.com] Sent: Thursday, March 26, 2009 12:52 PM To: NT System Admin Issues Subject: Re: Force workstation restart On Thu, Mar 26, 2009 at 11:09 AM, John Aldrich <jaldr...@blueridgecarpet.com> wrote: > IS there an easy way to have a server-initiated workstation restart? I call the following batch file "reboot_the_world.CMD". @ECHO OFF REM SYNOPSIS REM REM reboot_the_world [force] <action> <match...> [ /EXCLUDE <exclusion...> ] REM REM OVERVIEW REM REM Reboots or shuts down computers matching a name pattern. You can also exclude items. REM REM USAGE REM REM * <action> is one of "list", "reboot", or "shutdown". The "list" action simply displays names without shutting down or rebooting anything. REM * <force>, if specified, is a literal string, prefixing the action. It tells the shutdown command to do a force-close, rather than a graceful-close, of any open user programs. REM * <match...> is one or more patterns, separated by spaces. Each pattern will be compared against the list of active computers, and matches are added to the list of reboot targets. REM * If the optional /EXCLUDE switch is used, <exclusion...> is one or more patterns, separated by spaces. Each pattern will be compared against the list of reboot targets, and filter out any matches. REM REM * Exclusions override matches. REM * Pattern matching and option-names are case-insensitive. REM * Pattern matching is a simple substring compare. Wildcards, regular expressions, etc., are not supported. REM * Dependant on the NetBIOS browse list (Network Neighborhood, My Network Places, etc.) to get active computers. REM * Forcing does NOT first attempt a graceful-close; it just kills user programs. REM REM PREREQUISITES REM REM Needs the SHUTDOWN utility from the Windows 2000 Resource Kit, renamed as "RKSHUTDOWN.EXE". SETLOCAL ENABLEEXTENSIONS REM #################### constants #################### REM grace period to give users before performing action SET ACTION_DELAY=120 REM temporary files (base names and/or paths) SET NETVIEW_OUT=%TEMP%\NETVIEW.OUT SET REBOOT_LIST=%TEMP%\REBOOT_LIST.TMP SET BEFORE_EXCLUDE_BASE=REBOOT_LIST_BEFORE_EXCLUDE.TMP & REM the RENAME command needs just base name for rename-to target SET BEFORE_EXCLUDE=%TEMP%\%BEFORE_EXCLUDE_BASE% REM #################### main program #################### REM -------------------- initialize -------------------- REM clear variables SET ACTION= SET FORCED= REM clean up any leftover temp files CALL :del_temp_files REM -------------------- arguments -------------------- REM check for forced action modifier IF /I "%1"=="force" ( REM when "force reboot" or "force shutdown" is specified, /C is added to force-close programs REM you can also "force list", but that's same as regular listing :) SET FORCE=/C SHIFT ) REM get action to perform, or abort if missing SET ACTION=%1 SHIFT IF NOT DEFINED ACTION ( ECHO ERROR: Missing argument. Specify action as first argument. GOTO :EOF & REM abort ) REM make sure user specifed a valid action IF /I %ACTION%==list GOTO valid_action IF /I %ACTION%==reboot GOTO valid_action IF /I %ACTION%==shutdown GOTO valid_action ECHO ERROR: Invalid action specified: %ACTION% GOTO :EOF & REM abort :valid_action REM make sure user specified at least one name pattern to match against IF "%1"=="" ( ECHO ERROR: Missing argument. Specify one or more computer name match patterns. GOTO :EOF & REM abort ) REM -------------------- generate/filter lists -------------------- ECHO Getting list of active network computers... NET VIEW > "%NETVIEW_OUT%" ECHO Finding matching names from list... :find_next_target FINDSTR /I /C:%1 "%NETVIEW_OUT%" >> "%REBOOT_LIST%" SHIFT IF /I "%1"=="/EXCLUDE" GOTO exclude_targets IF NOT "%1"=="" GOTO find_next_target GOTO :targets_done :exclude_targets ECHO Excluding matching names from list... SHIFT & REM remove /EXCLUDE from arg list REM make sure user gave us something to exclude IF "%1"=="" ( ECHO ERROR: Option /EXCLUDE given without patterns to exclude. GOTO :EOF & REM abort ) :exclude_next REM for each exclude pattern, previously output file becomes input file RENAME "%REBOOT_LIST%" "%BEFORE_EXCLUDE_BASE%" FINDSTR /V /I /C:%1 "%BEFORE_EXCLUDE%" > "%REBOOT_LIST%" SHIFT DEL "%BEFORE_EXCLUDE%" IF NOT "%1"=="" GOTO exclude_next GOTO targets_done REM -------------------- take action -------------------- :targets_done ECHO Performing action %ACTION% on remaining comuters (if any)... SET COUNT=0 FOR /F "usebackq" %%T IN ("%REBOOT_LIST%") DO ( REM always print the name (either as process indication, or as "action" for list) ECHO %%T IF /I %ACTION%==shutdown rkshutdown %%T /T:%ACTION_DELAY% %FORCE% IF /I %ACTION%==reboot rkshutdown %%T /R /T:%ACTION_DELAY% %FORCE% SET /A COUNT=COUNT + 1 ) REM -------------------- finish -------------------- ECHO Processed %COUNT% computers. CALL :del_temp_files GOTO :EOF & REM end of main program REM #################### sub-routines #################### :del_temp_files CALL :del_if_exist "%NETVIEW_OUT%" CALL :del_if_exist "%REBOOT_LIST%" CALL :del_if_exist "%BEFORE_EXCLUDE%" GOTO :EOF & REM return REM ---------------------------------------------------------------------- :del_if_exist IF EXIST "%1" DEL "%1" GOTO :EOF & REM return REM #################### END OF FILE #################### ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~