2

セッションで notepad.exe を開始しました。

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 の間のワイルドカード文字に関する問題ですが、フィルターを機能させるのを手伝ってくれる人はいますかCommandLine='C:\Windows\system32\notepad.exe'?

4

3 に答える 3

1

CommandLine プロパティの値には引用符が含まれているため、それらもエスケープする必要があります。

機能しているが恐ろしい文字列は次のとおりです。

gwmi -Query "Select * from Win32_Process where CommandLine = '`"c:\\windows\\system32\\notepad.exe`"'"
于 2011-10-06T11:44:50.463 に答える
0

引用符を含める必要がありますが、WQL でそれらをエスケープする方法を思い出すことができないため、PSH で行います。

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

フィルター式は二重引用符で囲まれ、文字列引数LIKEは単一引用符で囲まれています。その引数の一部である二重引用符は、PowerShell から引用する必要があります。

于 2011-10-06T11:59:41.633 に答える
0
Get-Process | ? {$_.Path -eq 'C:\Windows\system32\notepad.exe'}

Get-Process | ? {$_.processname -eq 'notepad'}
于 2011-10-12T10:21:08.210 に答える