Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

We are using vbs script to monitor the services in SAP application.Below script was already implemented.It is listing only some services in SAP .Please help me in the script to list all the services.Out of 60 services 20 are displaying.

Const ForAppending = 8
DIM prefix, prelen
DIM pattern
pattern="%"

Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objLogFile = objFSO.OpenTextFile("services.csv", ForAppending, True)
Set objLogFile = Wscript.StdOut
'objLogFile.Write("Service Dependencies")
objLogFile.Writeline
strComputer = "."

DIM name

if WScript.Arguments.length = 1 then
pattern = WScript.Arguments(0)
end if

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
query = "Select * from Win32_Service where Name like '" & pattern & "' AND ServiceType = 'Own Process' OR ServiceType='Interactive Process'"
WScript.Echo query

Set colListOfServices = objWMIService.ExecQuery(query)

prefix = "C:\WINDOWS\"
prelen = len(prefix)
For Each objService in colListofServices
If not startsWith(objService.PathName,prefix,prelen) Then
objLogFile.Write " service_name=" & objService.Name & ";service_type=ntsrv;service_caption=" & objService.DisplayName& ";service_user=" & objService.StartName & ";service_Executable=" & objService.PathName & ";service_resources=serviceName_"&objService.Name
objLogFile.WriteLine
End If
Next
objLogFile.Close


Function startsWith(str1, prefix,prelen)
startsWith = Left(LCase(str1),prelen) = LCase(prefix)

End Function

Thanks,
karthik

What I have tried:

I have tried changing this query = "Select * from Win32_Service"
Posted
Updated 23-Sep-16 1:58am

1 solution

It is going to be a problem with your WHERE clause in
VB
query = "Select * from Win32_Service where Name like '" & pattern & "' AND ServiceType = 'Own Process' OR ServiceType='Interactive Process'"

For a start you have a mixture of AND and OR without using brackets to define your meaning. Try this instead (note the open & close brackets)
VB
query = "Select * from Win32_Service where Name like '" & pattern & "' AND ( ServiceType = 'Own Process' OR ServiceType='Interactive Process' ) "


If you are still not getting all the results you expect after that then check your input for pattern
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900