You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Get-WmiObject调用Win32_process的Create方法失败,求替代[WMICLASS]方案

Alternative to [WMICLASS] for executing commands via WMI in PowerShell

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.

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-WmiObject or Get-CimClass are allowed by your environment's policies.

内容的提问来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:40:32