Re: Stop multiple services and restart server

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Torvier,

Does "NET.EXE" automatically stop services dependent on the the service it's stopping as well?

I have a similar script (which I can't post because of an NDA) which is a lot more complex than what you have because of the
requirement to stop dependent services first (I have a recursive WMI function which stops dependencies along the "dependency tree").

Of course one can always list the services to be stopped in the right order within the script.

Regards,
Ato

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@xxxxxxxxx> wrote in message news:erw%23DnpRFHA.3356@xxxxxxxxxxxxxxxxxxxxxxx
> Lou wrote:
>
> > Hello! I 'm new to scripting and need a scrtipt *.vbs to stop
> > about four services and restart the server.
> Hi
>
>
> '--------------------8<----------------------
>
> Set oShell = CreateObject("WScript.Shell")
>
> ' list your service names here
> aServices = Array("DNS Server", "DHCP Server", "Some service")
>
> For Each sService In aServices
> oShell.Run "Net.exe stop " & Chr(34) & sService & Chr(34), 0, True
> Next
>
> ShutDown ".", "Reboot"
>
>
> Sub ShutDown(sNode, sAction)
>
> ' First parameter:
> ' use "." for local computer
>
> ' Second parameter:
> ' Use "PowerOff" for a poweroff
> ' Use "PowerOff_Force" for a forced poweroff
> ' Use "Shutdown" for a shutdown
> ' Use "Shutdown_Force" for a forced shutdown
> ' Use "Reboot" for a reboot
> ' Use "Reboot_Force" for a forced reboot
> ' Use "LogOff" for a logoff
> ' Use "LogOff_Force" for a forced logoff
>
> Const EWX_LOGOFF = 0
> Const EWX_SHUTDOWN = 1
> Const EWX_REBOOT = 2
> Const EWX_FORCE = 4
> Const EWX_POWEROFF = 8
>
> On Error Resume Next
> Set oWMI = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate,(Shutdown)}!\\" _
> & sNode & "\root\cimv2")
>
> Set colOperatingSystems = oWMI.ExecQuery _
> ("Select * from Win32_OperatingSystem")
> For Each obj in colOperatingSystems
> Set oOS = obj : Exit For
> Next
> If Err.Number <> 0 Then
> WScript.Echo "Could not connect to " & sNode
> Exit Sub
> End If
>
> sAction = LCase(sAction)
>
> Select Case sAction
> Case "logoff"
> iCmd = EWX_LOGOFF
> Case "logoff_force"
> iCmd = EWX_LOGOFF + EWX_FORCE
> Case "shutdown"
> iCmd = EWX_SHUTDOWN
> Case "shutdown_force"
> iCmd = EWX_SHUTDOWN + EWX_FORCE
> Case "reboot"
> iCmd = EWX_REBOOT
> Case "reboot_force"
> iCmd = EWX_REBOOT + EWX_FORCE
> Case "poweroff"
> iCmd = EWX_POWEROFF
> Case "poweroff_force"
> iCmd = EWX_POWEROFF + EWX_FORCE
> Case Else
> MsgBox "Error: invalid input parameter!", _
> vbExclamation + vbSystemModal, "ShutDown"
> End Select
>
> oOS.Win32shutdown iCmd
>
> End Sub
> '--------------------8<----------------------
>
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx


.



Relevant Pages

  • Re: Disconnect user after closed IE
    ... ' will ' actually end up as a forced shutdown (a bug in the WMI ... use "Logoff" instead of "Logoff_Force". ... Const EWX_SHUTDOWN = 1 ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.scripting.wsh)
  • Re: License Agreement, Required to Scroll
    ... get to the button without scrolling to the bottom of the page. ... This is probably the most effect solution...not dependent on scripting, ...
    (alt.html)
  • Re: License Agreement, Required to Scroll
    ... get to the button without scrolling to the bottom of the page. ... This is probably the most effect solution...not dependent on scripting, ...
    (alt.html)
  • Re: Regular Expressions
    ... Const OpenAsASCII = 0 ... Set oFSO = CreateObject ... bCheckForG1AtNextLoop = False ' init value ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.inetsdk.programming.scripting.vbscript)
  • Re: Get & Set Services status per script ?
    ... Const OpenAsASCII = 0 ... sComputer = oWshNet.ComputerName ... On Error Goto 0 ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.vbscript)