所有服务都没有列出 [英] All services are not listing

查看:61
本文介绍了所有服务都没有列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们正在使用vbs脚本来监控SAP application.Below脚本中的服务已经实现了。它只列出了SAP中的一些服务。请帮助我在脚本中列出了所有服务。显示了60个服务中的20个。



Const ForAppending = 8

DIM前缀,prelen

DIM模式

pattern =%



设置objFSO = CreateObject(Scripting.FileSystemObject)

'设置objLogFile = objFSO.OpenTextFile(services.csv,ForAppending,True)

设置objLogFile = Wscript.StdOut

'objLogFile .Write(Service Dependencies)

objLogFile.Writeline

strComputer =。



DIM名称



如果WScript.Arguments.length = 1那么

pattern = WScript.Arguments(0)

end如果



设置objWMIService = GetObject(winmgmts:&{impersonationLevel = impersonate}!\\& ; strComputer& \ root \ cimv2)

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

WScript.Echo查询



设置colListOfServices = objWMIService。 ExecQuery(查询)



prefix =C:\ WINDOWS \

prelen = len(前缀)

对于colListofServices中的每个objService

如果不是startsWith(objService.PathName,prefix,prelen)那么

objLogFile.Writeservice_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

结束如果

下一页

objLogFile 。关闭





函数startsWith(str1,prefix,prelen)

startsWith = Left(LCase(str1) ),prelen)= LCase(前缀)



结束功能



谢谢,

karthik



我尝试了什么:



我有尝试更改此查询=从Win32_Service中选择*

解决方案



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


这篇关于所有服务都没有列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆