使用Get-WmiObject调用Win32_process的Create方法失败,求替代[WMICLASS]方案
First, let's break down why your initial code threw that error: when you use Get-WmiObject -Class Win32_process, you're pulling existing process instances from the remote machine. The Create method is a static method belonging to the Win32_process class itself, not a method attached to individual process instances. That's why you got the "Create method doesn't exist" message.
Here are two solid workarounds that avoid the [WMICLASS] type accelerator while getting the job done:
1. Use Get-WmiObject with the -List parameter to fetch the class object
Instead of retrieving running processes, grab the Win32_process class definition directly, then call its static Create method:
$command = "taskkill /F /IM aaaa.exe" # Get the Win32_process class (not active process instances) $processClass = Get-WmiObject -Class Win32_process -ComputerName 1.1.1.1 -List $result = $processClass.Create($command)
This matches the behavior of your working [WMICLASS] code but uses standard WMI cmdlets that should play nicely with your application.
2. Use CIM Cmdlets (Modern, Recommended Replacement)
WMI cmdlets like Get-WmiObject are deprecated in newer PowerShell versions. The CIM cmdlets are the supported alternative, and they work similarly to invoke the static Create method:
$command = "taskkill /F /IM aaaa.exe" # Retrieve the Win32_process class via CIM $processClass = Get-CimClass -ClassName Win32_process -ComputerName 1.1.1.1 -Namespace ROOT\CIMV2 # Call the static Create method with your command $result = Invoke-CimMethod -CimClass $processClass -MethodName Create -Arguments @{CommandLine = $command}
This approach is more robust, supports modern PowerShell features, and skips the [WMICLASS] accelerator that's causing issues in your environment.
Quick Notes:
- Ensure your user account has the necessary WMI/CIM permissions on the remote machine (1.1.1.1) to create or terminate processes.
- If you're working in a restricted execution context, double-check that
Get-WmiObjectorGet-CimClassare allowed by your environment's policies.
内容的提问来源于stack exchange,提问作者John

