|
-
Sep 19th, 2016, 03:52 AM
#1
Thread Starter
Member
VB script for window services
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(stopped and running) .Please help me in the script to list all the services.
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|