Showing Service Information using VBS and ADSI

02/11/07

Permalink 06:43:19 am, by dave Email , 863 words, 177 views   English (US)
Categories: Windows Scripting, Wsh Scripts

Showing Service Information using VBS and ADSI

Here is a fairly straight forward example of enumerating all the services on a window's machine using ADSI.

If you wanted to bind to the machine you are querying with different credentials, you could replace the getobject call in the showServices subroutine with an opendsobject call.

[More:]


'----------------------------------------------------------
'-- showSvc.vbs
'-- example of displaying windows service information
'-- using the WinNT ADSI provider
'----------------------------------------------------------
dim compName, args, argCount

set args = wscript.arguments
argCount = args.Count

if argCount = 0 then
     wscript.echo "Usage: cscript showSvc.vbs <computer name>"
     wscript.quit(1)
else
     compName = args.item(0)
end if

showServices compName

set args = nothing

wscript.quit()

'----------------------------------------------------------
'-- showServices
'-- this sub actually lists all of the services on the
'-- target machine and the most common standard properties
'----------------------------------------------------------
sub showServices( computer )
      dim comp, svc

      set comp = getobject( "WinNT://" + computer + ",Computer" )

      comp.filter = array("Service")

      for each svc In comp

           wscript.echo "Service Name: " & svc.name
           wscript.echo "Service Status: " & getSvcStatus( svc.status )
           wscript.echo "Service Class: " & svc.class
           wscript.echo "Service DisplayName: " & svc.displayname
           wscript.echo "Service Error Control: " & svc.errorcontrol
           wscript.echo "Service ADsPath: " & svc.adspath
           wscript.echo "Service GUID: " & svc.guid
           wscript.echo "Service Host: " & svc.hostcomputer
           wscript.echo "Service Load Order: " & svc.loadordergroup
           wscript.echo "Service Parent: " & svc.parent
           wscript.echo "Service Path: " & svc.path
           wscript.echo "Service Schema: " & svc.schema
           wscript.echo "Service Account Name: " & svc.serviceaccountname
           wscript.echo "Service Type: " & svc.servicetype
           wscript.echo ""

           '--------------------------------------------------
           '-- These attributes may also be available, depending
           '-- on a specific service. These have been removed
           '-- due to them not being available on all standard
           '-- window's services.
           '--------------------------------------------------
           'wscript.echo "Service Account Paths: " & svc.serviceaccountpath
           'wscript.echo "Service Dependencies: & svc.dependencies
           'wscript.echo "Service Start Type: " & svc.startype
           'wscript.echo "Service Startup Params: " & svc.startupparameters
           'wscript.echo "Service Version: " & svc.version

      next

      set comp = nothing

end sub

'----------------------------------------------------------
'-- getSvcStatus
'-- this function translates a numeric value into a more
'-- user friendly status
'----------------------------------------------------------
function getSvcStatus( status )

      if status = 1 then
           getSvcStatus = "Stopped"
      elseif status = 2 then
           getSvcStatus = "Start Pending"
      elseif status = 3 then
           getSvcStatus = "Stop Pending"
      elseif status = 4 then
           getSvcStatus = "Running"
      elseif status = 5 then
           getSvcStatus = "Continue Pending"
      elseif status = 6 then
           getSvcStatus = "Pause Pending"
      elseif status = 7 then
           getSvcStatus = "Paused"
      elseif status = 8 then
           getSvcStatus = "Service Error"
      else
           getSvcStatus = "Unknown Status"
      end if

end function

I hope this post helped you out. If it didn't, I am always looking for new scripts to add so submit a request for your question or need and I will see if I can answer it.



Did you like this post? If so, Share it!  del.icio.us digg reddit slashdot this article Facebook Twitter MySpace Email



Pingbacks:

No Pingbacks for this post yet...

This post has 5 feedbacks awaiting moderation...

Scripts

This is somewhere I can post interesting snippets as I come across them. Hopefully some folks out there will find this helpful.

Search

Follow Me:

Misc

Who's Online?

  • Guest Users: 2

powered by b2evolution free blog software