Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Tue, 4 Mar 2008 08:36:30 -0800 (PST),    group: microsoft.public.win32.programmer.wmi        back       


Problem with path name with space in it win32_services   
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..
date: Tue, 4 Mar 2008 08:36:30 -0800 (PST)   author:   twpps

Re: Problem with path name with space in it win32_services   
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..
date: Tue, 4 Mar 2008 14:38:32 -0500   author:   mayayana

RE: Problem with path name with space in it win32_services   
"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
date: Tue, 4 Mar 2008 13:32:01 -0800   author:   urkec

RE: Problem with path name with space in it win32_services   
"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
date: Tue, 4 Mar 2008 13:51:02 -0800   author:   urkec

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us