Startup and Shutdown Scripts
Configuring System Startup DelayEnumerating the Boot Configuration Properties of a Computer
Enumerating Recovery Configuration Options
Enumerating Computer Startup Commands
Enumerating Computer Startup Options
Modifying Recovery Configuration Options
Restarting a Computer
Shutting Down the Local Computer
Configuring System Startup Delay
Configures a computer to wait 10 seconds (instead of the default 30 seconds) before automatically loading the default operating system upon startup.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colStartupCommands = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objStartupCommand in colStartupCommands objStartupCommand.SystemStartupDelay = 10 objStartupCommand.Put_ Next
Enumerating the Boot Configuration Properties of a Computer
Returns boot configuration information for a computer.
On Error Resume Next strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_BootConfiguration") For Each objItem in colItems Wscript.Echo "Boot Directory: " & objItem.BootDirectory Wscript.Echo "Configuration Path: " & objItem.ConfigurationPath Wscript.Echo "Description: " & objItem.Description Wscript.Echo "Last Drive: " & objItem.LastDrive Wscript.Echo "Name: " & objItem.Name Wscript.Echo "Scratch Directory: " & objItem.ScratchDirectory Wscript.Echo "Setting ID: " & objItem.SettingID Wscript.Echo "Temp Directory: " & objItem.TempDirectory Next
Enumerating Recovery Configuration Options
Returns a list of settings that indicate the action to be taken by a computer should a stop event (blue screen) occur.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colRecoveryOptions = objWMIService.ExecQuery _ ("Select * from Win32_OSRecoveryConfiguration") For Each objOption in colRecoveryOptions Wscript.Echo "Auto reboot: " & objOption.AutoReboot Wscript.Echo "Debug File Path: " & objOption.DebugFilePath Wscript.Echo "Debug Info Type: " & objOption.DebugInfoType Wscript.Echo "Kernel Dump Only: " & objOption.KernelDumpOnly Wscript.Echo "Name: " & objOption.Name Wscript.Echo "Overwrite Existing Debug File: " & _ objOption.OverwriteExistingDebugFile Wscript.Echo "Send Administrative Alert: " & objOption.SendAdminAlert Wscript.Echo "Write Debug Information: " & objOption.WriteDebugInfo Wscript.Echo "Write to System Log: " & objOption.WriteToSystemLog Next
Enumerating Computer Startup Commands
Enumerates all startup commands on a computer, including those found in the Startup folder and those found in the Registry.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colStartupCommands = objWMIService.ExecQuery _ ("Select * from Win32_StartupCommand") For Each objStartupCommand in colStartupCommands Wscript.Echo "Command: " & objStartupCommand.Command Wscript.Echo "Description: " & objStartupCommand.Description Wscript.Echo "Location: " & objStartupCommand.Location Wscript.Echo "Name: " & objStartupCommand.Name Wscript.Echo "SettingID: " & objStartupCommand.SettingID Wscript.Echo "User: " & objStartupCommand.User Next
Enumerating Computer Startup Options
Returns a list of startup options for a computer, including the startup delay time and other information found in Boot.ini.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colStartupCommands = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objStartupCommand in colStartupCommands Wscript.Echo "Reset Boot Enabled: " & _ objStartupCommand.AutomaticResetBootOption Wscript.Echo "Reset Boot Possible: " & _ objStartupCommand.AutomaticResetCapability Wscript.Echo "Boot State: " & objStartupCommand.BootupState Wscript.Echo "Startup Delay: " & objStartupCommand.SystemStartupDelay For i = 0 to Ubound(objStartupCommand.SystemStartupOptions) Wscript.Echo "Startup Options: " & _ objStartupCommand.SystemStartupOptions(i) Next Wscript.Echo "Startup Setting: " & _ objStartupCommand.SystemStartupSetting Next
Modifying Recovery Configuration Options
Configures a computer to do a complete memory dump to the file C:\Scripts\memory.dmp should a stop event (blue screen) occur.
Const COMPLETE_MEMORY_DUMP = 1 strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colRecoveryOptions = objWMIService.ExecQuery _ ("Select * from Win32_OSRecoveryConfiguration") For Each objOption in colRecoveryOptions objOption.DebugInfoType = COMPLETE_MEMORY_DUMP objOption.DebugFilePath = "c:\scripts\memory.dmp" objOption.OverWriteExistingDebugFile = False objOption.Put_ Next
Restarting a Computer
Restarts a computer.
strComputer = "atl-dc-01" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _ strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems ObjOperatingSystem.Reboot() Next
Shutting Down the Local Computer
Shuts down the local computer.
Set colOperatingSystems = GetObject_ ("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems ObjOperatingSystem.Win32Shutdown(1) Next