Hi all I got a little issue with a query. i'm looking for a service name from a running process. I've found a really interesting code on the microsoft site. List Services Running in a Process http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx?mfr=true the process is running.. but the path go a space in it. i've been playing if the quote but it always return nothing. strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root \cimv2") Set colListOfServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where PathName = ""C:\\Program Files\ \McAfee\\VirusScan Enterprise\\Mcshield.exe""") WScript.Echo colListOfServices.count For Each objService In colListOfServices Wscript.Echo objService.DisplayName Next any help is greatly apreciated..
That appears to be VBScript, in which case there's no escaping "\". "C:\\Program Files" is an invalid path. > I got a little issue with a query. i'm looking for a service name from > a running process. I've found a really interesting code on the > microsoft site. > > List Services Running in a Process > http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx?mfr=true > > the process is running.. but the path go a space in it. i've been > playing if the quote but it always return nothing. > > > strComputer = "." > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root > \cimv2") > > Set colListOfServices = objWMIService.ExecQuery _ > ("Select * from Win32_Service Where PathName = ""C:\\Program Files\ > \McAfee\\VirusScan Enterprise\\Mcshield.exe""") > > WScript.Echo colListOfServices.count > > For Each objService In colListOfServices > Wscript.Echo objService.DisplayName > Next > > any help is greatly apreciated..
"twpps" wrote: > Hi all > > I got a little issue with a query. i'm looking for a service name from > a running process. I've found a really interesting code on the > microsoft site. > > List Services Running in a Process > http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx?mfr=true > > the process is running.. but the path go a space in it. i've been > playing if the quote but it always return nothing. > > > strComputer = "." > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root > \cimv2") > > Set colListOfServices = objWMIService.ExecQuery _ > ("Select * from Win32_Service Where PathName = ""C:\\Program Files\ > \McAfee\\VirusScan Enterprise\\Mcshield.exe""") > > WScript.Echo colListOfServices.count > > For Each objService In colListOfServices > Wscript.Echo objService.DisplayName > Next > > any help is greatly apreciated.. > Maybe you can use ProcessId instead of PathName: strComputer = "." strProcessName = "spoolsv.exe" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colProcesses = objWMIService.ExecQuery _ ("Select * From Win32_Process " _ & "Where Name = '" & strProcessName & "'") For Each objProcess In colProcesses Set colServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where " & _ "ProcessId = " & objProcess.ProcessId) For Each objService in colServices Wscript.Echo objService.DisplayName WScript.Echo objService.PathName Next Next Looking in Win32_Service.PathName, some paths that have spaces (like C:\Program Files..) are enclosed in double quotes and some aren't. Maybe that is why your query doesn't work. -- urkec
"urkec" wrote: > "twpps" wrote: > > > Hi all > > > > I got a little issue with a query. i'm looking for a service name from > > a running process. I've found a really interesting code on the > > microsoft site. > > > > List Services Running in a Process > > http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx?mfr=true > > > > the process is running.. but the path go a space in it. i've been > > playing if the quote but it always return nothing. > > > > > > strComputer = "." > > Set objWMIService = GetObject("winmgmts:" _ > > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root > > \cimv2") > > > > Set colListOfServices = objWMIService.ExecQuery _ > > ("Select * from Win32_Service Where PathName = ""C:\\Program Files\ > > \McAfee\\VirusScan Enterprise\\Mcshield.exe""") > > > > WScript.Echo colListOfServices.count > > > > For Each objService In colListOfServices > > Wscript.Echo objService.DisplayName > > Next > > > > any help is greatly apreciated.. > > > > Maybe you can use ProcessId instead of PathName: > > > strComputer = "." > strProcessName = "spoolsv.exe" > > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" _ > & strComputer & "\root\cimv2") > > Set colProcesses = objWMIService.ExecQuery _ > ("Select * From Win32_Process " _ > & "Where Name = '" & strProcessName & "'") > > For Each objProcess In colProcesses > > Set colServices = objWMIService.ExecQuery _ > ("Select * from Win32_Service Where " & _ > "ProcessId = " & objProcess.ProcessId) > > For Each objService in colServices > Wscript.Echo objService.DisplayName > WScript.Echo objService.PathName > Next > > Next > > Looking in Win32_Service.PathName, some paths that have spaces (like > C:\Program Files..) are enclosed in double quotes and some aren't. Maybe that > is why your query doesn't work. > For paths with no double quotes around them the query worked with single quotes: "Select * from Win32_Service Where PathName = 'C:\\Program Files\\Microsoft Analysis Services\\Bin\\msmdsrv.exe'" For paths with double quotes I needed to add two to the query string: "Select * from Win32_Service Where PathName = '""C:\\Program Files\\Microsoft Virtual Server\\vssrvc.exe""'" -- urkec