Re: script to check services by Tim
Tim
Mon Aug 22 08:29:16 CDT 2005
Lynn,
The script below prompts you for a PC name, it then writes a text file
of all the services on the PC supplied, along with their current state
and Start mode. With a little modification, you should be able to get
it to do *exactly* what you require.
Sample output from the file that the script produces looks like:
1 of 104
Name=Alerter
State=Stopped
Start Mode=Disabled
-------------------
2 of 104
Name=Application Layer Gateway Service
State=Running
Start Mode=Manual
-------------------
The script follows:
----------------------------------------------------------------------
Option Explicit
Dim strComputer
Dim strMsg
Dim wbemServices
Dim wbemObjectSet
Dim x
Dim y
Dim z
Dim wbemObject
Dim arrServices()
Dim numEntries
Dim FSO
Dim OutFile
Dim shell
Dim FileName
strComputer = InputBox("Enter the name of the PC",WScript.ScriptName)
If strComputer = "" Then
WScript.Quit
End If
'strComputer="blue8\"&strComputer
FileName = "ServicesOn_"&strComputer&".txt"
Set wbemServices = GetObject("winmgmts:\\" & strComputer)
Set wbemObjectSet = wbemServices.InstancesOf("Win32_Service")
For Each wbemObject In wbemObjectSet
On Error Resume Next
numEntries=UBound(arrServices)
If Err Then
numEntries = 0
End If
On Error Goto 0
'MsgBox numEntries
numEntries=numEntries+1
ReDim Preserve arrServices(numEntries)
arrServices(numEntries-1)="Name="&wbemObject.DisplayName
&vbCrLf&"State="&wbemObject.State&vbCrLf&"Start
Mode="&wbemObject.StartMode
Next
Set FSO = CreateObject("Scripting.FileSystemObject")
Set OutFile = FSO.OpenTextFile(FileName,2,true)
For y = 0 To UBound(arrServices)-1
OutFile.WriteLine y+1 & " of " & UBound(arrServices) & vbCrLf &
arrServices(y) &vbCrLf & "-------------------"
Next
OutFile.Close
Set shell = CreateObject("WScript.Shell")
shell.Run "notepad "&FileName,,false
'WScript.Sleep 1000
'FSO.DeleteFile FileName
---------------------------------------------------------------------------
Regards, Tim