[intertech] VBS Script to Query Services

  • From: "Brian Smyth" <mail@xxxxxxxxxxxxxx>
  • To: <intertech@xxxxxxxxxxxxx>
  • Date: Thu, 18 Nov 2004 17:15:47 -0000

Mark,

 

I have attached the script to query the services. Download it to your
computer rename it to .vbs

 

You will have to edit line 27 and change "bs-compaq" to whatever
computername you want to monitor

 

 

Double click

Wait about ten seconds

 

 

Cheers,

Brian

Dim objFileSys
Dim objIntExplorer
Dim objWshShell
Dim strDesktop
Dim intCounter          'General counter


'Initialize common scripting objects
Set objFileSys    = CreateObject( "Scripting.FileSystemObject" )
Set objWshNetwork = CreateObject( "WScript.Network" )
Set objWshShell   = CreateObject( "WScript.Shell" )


'Setup IE for use as a status message window
Call SetupIE

'Details required to grab services
strText = ""
strWMIMoniker = "WinMgmts:!//bs-compaq"
strQuery = "select * from Win32_Service"


'Display welcome message
Call UserPrompt ("<Body BGColor=""#cccccc"">")
Call UserPrompt ("<div align=""center""><img src=""IntertechSmall.JPG"" width = 
""133"" height=""46"">")
Call UserPrompt ("<div align=""left""><font size=""5"" face=""Arial, Helvetica, 
sans-serif""><B> Service Details</B></Font>")
Call UserPromptLine

strText = ""
strWMIMoniker = "WinMgmts:!//bs-compaq"
strQuery = "select * from Win32_Service"

Set wmiWin32Services = GetObject(strWMIMoniker).ExecQuery(strQuery)


For Each wmiWin32Service in wmiWin32Services
                Call UserPrompt (wmiWin32Service.startname)
                Call UserPrompt (wmiWin32Service.systemname)
                Call UserPrompt (wmiWin32Service.state)
                Call UserPrompt (wmiWin32Service.name)
                Call UserPrompt (wmiWin32Service.caption)
                Call UserPrompt (wmiWin32Service.started)
                Call UserPrompt (wmiWin32Service.status)
                Call UserPrompt (wmiWin32Service.startmode)
                Call UserPrompt (wmiWin32Service.description & vbCrLf)
Call UserPromptNewLine


Next
WScript.Echo strText


Call UserPromptLine
Call UserPrompt ("The System Service Analyzer has Completed. Thank You!!!!")



Wscript.Sleep (1500)
'objIntExplorer.Quit( )

'Call Cleanup























'#########################################################################################################################
'       FUNCTIONS AND SUB-ROUTINES
'#########################################################################################################################





'##########################################################################################
'   Set up Internet Explorer for use as a status message window
'##########################################################################################
Private Sub SetupIE

  On Error Resume Next

  Dim strTitle    'Title of IE window
  Dim intCount    'Counter used during AppActivate

  strTitle = "Intertech Ireland Script Processor"

  'Create reference to objIntExplorer
  'This will be used for the user messages. Also set IE display attributes
  Set objIntExplorer = Wscript.CreateObject("InternetExplorer.Application")
  With objIntExplorer
    .Navigate "about:blank"
    .ToolBar   = 0
    .Menubar   = 0
    .StatusBar = 0
    .Width     = 700
    .Height    = 550
    .Left      = 1
    .Top       = 1
  End With

  'Set some formating
  With objIntExplorer.Document
    .WriteLn ("<!doctype html public>")
    .WriteLn   ("<head>")
    .WriteLn    ("<title>" & strTitle & "</title>")
    .WriteLn     ("<style type=""text/css"">")
    .WriteLn      ("body {text-align: left; font-family: arial; font-size: 
10pt}")
    .WriteLn     ("</style>")
    .WriteLn   ("</head>")
  End With

  'Wait for IE to finish
  Do While (objIntExplorer.Busy)
    Wscript.Sleep 200
  Loop

  'Show IE
  objIntExplorer.Visible = 1

  'Make IE the active window
  For intCount = 1 To 100
    If objWshShell.AppActivate(strTitle) Then Exit For
    WScript.Sleep 50
  Next

End Sub


'##########################################################################################
'   UserPrompt: Add a line of text to the Script processor Windows
'   UserPromptLine: Add a horizontal line to the Script processor Windows
'   UserPromptNewLine: Add a new line to the Script processor Windows
'##########################################################################################
Private Sub UserPrompt( strPrompt )

  On Error Resume Next

  objIntExplorer.Document.WriteLn (strPrompt & "<br />")

End Sub

Private Sub UserPromptLine

  On Error Resume Next

  objIntExplorer.Document.WriteLn ("<hr style=""width:100%""></hr>")

End Sub

Private Sub UserPromptNewLine

  On Error Resume Next

  objIntExplorer.Document.WriteLn ("<P>&nbsp;</P>")

End Sub



'##########################################################################################
'   Empties all the variables of data
'##########################################################################################
Sub Cleanup'

  On Error Resume Next

  Set objFileSys     = Nothing
  Set objWshNetwork  = Nothing
  Set objWshShell    = Nothing
  Set objIntExplorer = Nothing

  'Exit script
  Wscript.Quit( )

End Sub

Other related posts: