2011-10-06 57 views
2

我有一个NOTEPAD.EXE在我的会议开始:故障与WMI过滤

gwmi -Query "Select CommandLine from Win32_Process where CommandLine='C:\Windows\system32\notepad.exe'" 

Get-WmiObject : Demande non valide 
Au niveau de ligne : 1 Caractère : 5 
+ gwmi <<<< -Query "Select CommandLine from Win32_Process where CommandLine='C:\Windows\system32\notepad.exe'" 
    + CategoryInfo   : InvalidOperation: (:) [Get-WmiObject], ManagementException 
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand 

我测试:

gwmi -Query "Select CommandLine from Win32_Process where CommandLine='C:\\Windows\\system32\\notepad.exe'" 

它给什么

gwmi -Query "Select CommandLine from Win32_Process where CommandLine LIKE '%C:\\Windows\\system32\\notepad.exe%'" 

完美的作品

__GENUS   : 2 
__CLASS   : Win32_Process 
__SUPERCLASS  : 
__DYNASTY  : 
__RELPATH  : 
__PROPERTY_COUNT : 1 
__DERIVATION  : {} 
__SERVER   : 
__NAMESPACE  : 
__PATH   : 
CommandLine  : "C:\Windows\system32\notepad.exe" 

也许是使用PowerShell和WMI之间通配符caracters一个麻烦,但任何人都可以帮我做过滤CommandLine='C:\Windows\system32\notepad.exe'工作

+0

在找到的(找到的)'Win32_Process'实例上'CommandLine'的值是多少?例如。这里'CommandLine'的值包含双引号。 – Richard

+0

我编辑问题以显示值如果属性,它的工作。 如果你看看WMBEMTEST.EXE'CommandLine'是'WIN32_Process'的一个属性。 – JPBlanc

+0

问题是CommandLine被gwmi查询中的“。how escape”包围了吗? –

回答

1

命令行属性的值包含引号,所以他们需要也逃脱了。

一个工作,但可怕的字符串是:

gwmi -Query "Select * from Win32_Process where CommandLine = '`"c:\\windows\\system32\\notepad.exe`"'" 
+0

你测试过了吗?什么都不返回 –

+0

我转过身来,感谢那正是我在寻找的东西。我只是没有看到在WBEMTEST.EXE中有“”。 – JPBlanc

+0

@Christian - 是的,适合我。你装了记事本吗? :) – craika

0

您需要包括引号,但我不记得如何逃脱他们WQL,我会做的PSH:

gwmi -class Win32_Process -filter "CommandLine like '`"C:\\Windows\\system32\\notepad.exe`"'" 

过滤器表达式使用双引号,单引号中的字符串参数为LIKE。作为该参数一部分的双引号需要从PowerShell引用。

0
 
Get-Process | ? {$_.Path -eq 'C:\Windows\system32\notepad.exe'} 

Get-Process | ? {$_.processname -eq 'notepad'}