Avatar billede xion Nybegynder
15. maj 2007 - 11:25

Script som starter alle services som står til Automatic

Jeg leder efter et script som kan starte alle services der står til automatic, jeg skal bruge det ifm. noget overvågnings software som en Event Handler på service fejl. Første step skal der være at prøve at starte alle services der står til Automatic i Windows.

Jeg har noget kode fra tjek scriptet som kontrollere om alle services er startet, er der nogen der kan hjælpe med at tilrette dette så det isteddet for at kontrollere blot starter de services der står til automatic og som ikke er startet.

Scriptet:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' "chkwin_service_auto.wsf"
'
' Written by Jeff Stanley stanleyj@btusa.org
'
' 08.19.2003 ver 1.1
' Copyright (c) 2003 Jeff Stanley (stanleyj@btusa.org)
' --------------------------------------------------------------
' Checks for changes of Auto startup services.
'
'
' Credits for this program go to Ethan Galstad and Hagen Deike
' for the scripts design chkwin plugins, which I have copied and modified.
' Copyright (c) 1999-2001 Ethan Galstad/Hagen Deike (nagios@samurai.inka.de)
'


<job>
<runtime>
  <description>
chkwin_service_auto (nrpe_nt-plugin) 1.1
This nrpe_nt plugin come with ABSOLUTELY NO WARRANTY. You may redistribute
copies of the plugins under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.


This plugin checks In what state all Auto start services are. Returns a Critical
if any of the services are in a stopped state.  Will exit on first stopped service.
  </description>
  <named
    name="h"
    helpstring="Help"
    type="simple"
    required="false"
  />
  <named
    name="host"
    helpstring="Defines the netbios name of the system to monitor /host:name"
    type="simple"
    required="false"
  />
  />
  <example>
       
    You do not need a string for this plugin.
       
        chkwin_service_auto.wsf [/host:MySERVER]
   
    All Auto start services are running

    or..

    The Alerter Service has Stopped.
  </example>
</runtime>
<script language="VBScript">

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Const's and Var's
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Cons for return val's
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intUnknown = 3

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Help
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Wscript.Arguments.Named.Exists("h") Then
    Wscript.Echo "Plugin help screen:"
      Wscript.Arguments.ShowUsage()
      Wscript.Quit(intUnknown)
End If

If Wscript.Arguments.Named.Exists("host") Then
    strComputer = Wscript.Arguments.Named("host")
Else
    strComputer = "."
End If

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Main
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set colRunningServices = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2").ExecQuery("select * from Win32_Service where StartMode='Auto'")

'''''''''''''''''''''''''''''''''''''''''''''''''''
    For Each objService In colRunningServices
            If objService.Name = "SysmonLog" Then
                Wscript.Echo "All Automatic Services are Running"
                Wscript.Quit(intOK)
            Elseif objService.State = "Stopped" Then
                Wscript.Echo "The " & objService.Name & " service is Stopped"
                Wscript.Quit(intCritical)
            Elseif objService.State = "Start Pending" Then
                Wscript.Echo "The " & objService.Name & " service is Start Pending"
                Wscript.Quit(intWarning)
            Elseif objService.State = "Stop Pending" Then
                Wscript.Echo "The " & objService.Name & " service is Stop Pending"
                Wscript.Quit(intWarning)
            Elseif objService.State = "Continue Pending" Then
                Wscript.Echo "The " & objService.Name & " service is Continue Pending"
                Wscript.Quit(intWarning)
            Elseif objService.State = "Pause Pending" Then
                Wscript.Echo "The " & objService.Name & " service is Pause Pending"
                Wscript.Quit(intWarning)
            Elseif objService.State = "Paused" Then
                Wscript.Echo "The " & objService.Name & " service is Paused"
                Wscript.Quit(intCritical)
            Elseif objService.State = "Unknown" Then
                Wscript.Echo "The " & objService.Name & " " & Wscript.Arguments.Unnamed.Item(intCounter) & " service state is Unknown"
                Wscript.Quit(intUnknown)
            End If
    Next

Wscript.Echo "All Automatic Services are Running"
Wscript.Quit(intOK)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
</script>
</job>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester