我已经在我的会话中启动了notepad.exe:
gwmi -Query "Select CommandLine from Win32_Process where CommandLine='C:Windowssystem32notepad.exe'"
为
Get-WmiObject : Demande non valide
Au niveau de ligne : 1 Caractère : 5
+ gwmi <<<< -Query "Select CommandLine from Win32_Process where CommandLine='C:Windowssystem32notepad.exe'"
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
I test:
gwmi -Query "Select CommandLine from Win32_Process where CommandLine='C:\Windows\system32\notepad.exe'"
It is nothing
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:Windowssystem32notepad.exe"
也许是PowerShell和WMI之间通配符的问题,但是任何人都可以帮助我使过滤器CommandLine='C:Windowssystem32notepad.exe'
工作
CommandLine属性的值包含引号,因此它们也需要转义。
一个工作的,但可怕的字符串是:
gwmi -Query "Select * from Win32_Process where CommandLine = '`"c:\windows\system32\notepad.exe`"'"
您需要包含引号,但由于我不记得如何在WQL中转义它们,我将在PSH中完成:
gwmi -class Win32_Process -filter "CommandLine like '`"C:\Windows\system32\notepad.exe`"'"
过滤器表达式在双引号中,LIKE
的字符串参数在单引号中。参数中的双引号需要从PowerShell中引用。
Get-Process | ? {$_.Path -eq 'C:Windowssystem32notepad.exe'}
Get-Process | ? {$_.processname -eq 'notepad'}