且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

所有服务都没有列出

更新时间:2023-02-06 09:37:40



 query =  从Win32_Service中选择*其中名称如'&模式与 'AND ServiceType ='自己的流程'或ServiceType ='互动流程' 



首先,您可以混合使用AND和OR而不使用括号来定义您的意思。试试这个(注意开放和关闭括号)

 query =  从Win32_Service中选择*,其中Name为'&模式与 'AND(ServiceType ='自己的流程'或ServiceType ='互动流程') 





如果您仍未获得预期的所有结果,请检查您输入的模式


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"

It is going to be a problem with your WHERE clause in
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)

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