Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBS force reboot

38 views
Skip to first unread message

Kevin

unread,
Jun 27, 2001, 9:59:07 AM6/27/01
to
I have a script that is making changes to the network settings then needs to
force a reboot (as users tend to wonder why the settings don't take effect
when they fail to follow the directions and reboot).

Is there a vbs command to force a reboot?


jim_w

unread,
Jun 27, 2001, 4:48:38 PM6/27/01
to
hi Kevin,

This is a frequently asked question. Go to the google/deja search

http://groups.google.com/advanced_group_search

Type in reboot and "microsoft.public.scripting.wsh" for the group, you will
get over 200 hits.

cheers, jw

"Kevin" <kma...@mchs.com> wrote in message
news:ueBtcFx$AHA.1384@tkmsftngp03...

Ivana

unread,
Jun 27, 2001, 4:57:18 PM6/27/01
to

this should help

'to exit windows use this
set ws = WScript.CreateObject("WScript.shell")
ws.run "rundll32 shell32.dll,SHExitWindowsEx 1"
----------------------------------------------------------------------------
------------
'to reboot computer use this
set ws = WScript.CreateObject("WScript.shell")
ws.Run "RunDll32.exe Shell32.dll,SHExitWindowsEx 0x02"

----------------------------------------------------------------------------
-------------
'to logoff use
set ws = WScript.CreateObject("WScript.shell")
ws.run "rundll32 shell32.dll,SHExitWindowsEx 0"


Bryan Martin

unread,
Jun 27, 2001, 6:53:59 PM6/27/01
to
Dim WshShell
Main

'--------------------------------------------------------------------------

Sub Main()
Set WshShell = WScript.CreateObject("WScript.Shell")
MsgBox GetOS
If Left(GetOS(), 4) = "Win9" Or Left(GetOS(), 4) = "WinM" Then
MsgBox "redoing 98"
ForWin98
ElseIf Left(GetOS(), 4) = "Win2" Then
ForWin2k
Else
ForNT
End If
Set WshShell = nothing
End Sub
'--------------------------------------------------------------------------

Function GetOS()
Dim oFSO, oShell
Const sModule = "getOS"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Wscript.Shell")


Dim sOStype, sOSversion

On Error Resume Next
sOStype = oShell.RegRead(_
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control" & _
"\ProductOptions\ProductType")
If Err.Number<>0 Then
' Hex(Err.Number)="80070002"
' - Could not find this key, OS must be Win9x
Err.Clear
sOStype = oShell.RegRead(_
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows" & _
"\CurrentVersion\VersionNumber")
If Err.Number<>0 Then
GetOS = "Unknown Win9x"
' Could not pinpoint exact Win9x type
Exit Function ' >>>
End If
End If

If sOStype = "LanmanNT" _
OR sOStype = "ServerNT" _
OR sOStype = "WinNT" Then
Err.Clear
sOSversion = oShell.RegRead(_
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT" & _
"\CurrentVersion\CurrentVersion")
If Err.Number<>0 Then
GetOS = "Unknown NTx"
' Could not determine NT version
Exit Function ' >>>
End If
End If

If sOSversion = "4.0" Then
Select Case sOStype
Case "LanmanNT"
sOStype = "WinNT4-Srvr-DC"
' From HKLM\SYSTEM\CurrentControlSet\Control
' \ProductOptions\ProductType
Case "ServerNT"
sOStype = "WinNT4-Srvr"
' From HKLM\SYSTEM\CurrentControlSet\Control
' \ProductOptions\ProductType
Case "WinNT"
sOStype = "WinNT4-Wrkstat"
' From HKLM\SYSTEM\CurrentControlSet\Control
' \ProductOptions\ProductType
End Select
ElseIf sOSversion = "5.0" Then
sOStype = "Win2K"
Dim sTmp
sTmp = oShell.RegRead(_
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control" & _
"\ProductOptions\ProductType")
If sTmp = "WinNT" Then
sTmp = "-Wrkstat"
sOStype = sOStype & sTmp
ElseIf sTmp = "ServerNT" Then
sTmp = "-Srvr"
sOStype = sOStype & sTmp
Else
GetOS = "Unknown Win2K"
' Could not pinpoint exact Win2K type
Exit Function ' >>>
End If
Else
Select Case sOStype
Case "4.00.950"
sOStype = "Win95A"
Case "4.00.1111"
sOStype = "Win95B"
Case "4.03.1214"
sOStype = "Win95B"
Case "4.10.1998"
sOStype = "Win98"
Case "4.10.2222"
sOStype = "Win98SE"
Case "4.90.3000"
sOStype = "WinME" ' Windows Me
Case Else
MsgBox "sOStype = " & sOStype & vbCrLf & "Could not recognize" &_
" this particular OS. Please contact your system administrator.",_
vbCritical, "Error in module: " & sModule
End Select
End If
GetOS = sOStype
' --- CleanUp
Set oFSO = Nothing
Set oShell = Nothing
End Function

'--------------------------------------------------------------------------

Function ForWin2k()
Dim oShutdown, oOPSys
Set oShutdown =
GetObject("winmgmts:{impersonationlevel=impersonate,(shutdown)}").Execquery(
"Select * From win32_operatingsystem")
For Each oOPsys In oShutdown
oOPsys.win32shutdown(12)
Next
End Function
'--------------------------------------------------------------------------

Function ForNT()
WshShell.Run ("SHUTDOWN [/R] [/T:xx] [/C]")
' /R Specifies that the machine should reboot after shutdown.
' /T:xx Sets the timer for system shutdown in seconds. [20 sec. default]
' /C Forces running applications to close.


' Forces the Windows NT Workstation to reboot in 5 seconds.
WshShell.Run ("SHUTDOWN /R /T:5")
End Function

'--------------------------------------------------------------------------
Function ForWin98()
WshShell.Run ("rundll32.exe shell32.dll, SHExitWindowsEx 6")
' Where n is one, or a combination of one of the following numbers:
' - 0 - LOGOFF. Shuts down all running processes, then logs the user off.
' - 1 - SHUTDOWN. Shuts down the system to a point at which it is safe to
turn off the power.
' - 2 - REBOOT. Shuts down the system and then restarts the system.
' - 4 - FORCE. Forces processes to terminate.
' - 8 - POWEROFF. Shuts down the system and turns off the power.
' The above value options can be combined into one value to achieve
different results.
' WshShell.Run ("rundll32.exe shell32.dll, SHExitWindowsEx 6")
' restarts the Windows 98 after a 15 seconds delay
WshShell.Run ("runonce.exe -q")
End Function

Bryan Martin
Sp...@ahwayside.com


"Kevin" <kma...@mchs.com> wrote in message
news:ueBtcFx$AHA.1384@tkmsftngp03...

: I have a script that is making changes to the network settings then needs

:
:


0 new messages