Getting Windows services information using VBScript


Many times, we need to check if particular service is running or not on some particular server. Then we need to log into that server to check it.

To simplify it, I wrote a VBScript that will get the information for you from that server without login to the server.

Important NOTE: To get the service information, you need to run this VBScript with the account that has admin rights on the server for which you need the service information.

VBScript will point to below screen: Enter server name and click Ok.

clip_image002

It will create Service_Info.txt at the root location from where you are running the script.

Format of output log file:

Service Name::- Application Experience Lookup Service

Description::- Processes application compatibility lookup requests for applications as they are launched.

Status::- Running

Startup Type ::- Auto

Log on as ::- LocalSystem

VBScript Content:

'##############################################################
'#
'# Language     VBscript
'# 
'# Author       Mohd Aslam
'# Date         28.06.2011
'# Description  This script does following actions:
'#              1) it asks user to input the name of server 
'#                 whose service info you want
'#              2) It then creates Service_Info.txt file in 
'#                 the directory of the script file.
'#
'#############################################################

Dim oFSO              'File Scripting Object
Dim sScriptLog        'output log filename
Dim oScriptLog        'Script output file object
Dim oWshShell         'Windows Scripting Shell object

sScriptLog =    ".\Service_Info.txt"

Set oWshShell = WScript.CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oScriptLog =  oFSO.CreateTextFile (sScriptLog,True)
oScriptLog.Close()
Set oScriptLog = oFSO.OpenTextFile(sScriptLog,8)

InputServerName = InputBox("Enter the name of server whose service information you want:","Service Information") 

strComputer = InputServerName
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service")    
    
For Each objService in colRunningServices          
     oScriptLog.WriteLine "Service Name::- " & objService.DisplayName  & VbCrLf 
     oScriptLog.WriteLine "Description::- " & objService.Description  & VbCrLf 
     oScriptLog.WriteLine "Status::- " & objService.State & VbCrLf
     oScriptLog.WriteLine "Startup Type ::- " & objService.startmode & VbCrLf
     oScriptLog.WriteLine "Log on as ::- " & objService.startname & VbCrLf     
     oScriptLog.WriteLine "-------------------------------------------" & VbCrLf     
Next

                               –End of Article–

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s