2011-10-06 91 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'}