如何在新过程中通过PowerShell WMI创建新的环境更改

时间:2019-05-17 13:07:30

标签: wmi powershell-v2.0

我有相同的代码。 通过WMI创建新流程时如何传递新的环境更改($ ai.EnvironmentVariables =?)
我的示例不起作用,我发出了无效参数(21)

$procClass=[WMICLass]"win32_processstartup"
    $ai = $procClass.createinstance()
    $ai.ShowWindow = 1
    $ai.EnvironmentVariables = @('name', 'testvar')
    $ai.X = 0
    $ai.Y = 0
    $wmiclass = [wmiclass]"win32_process"
    $wmiMethodParameters = $wmiclass.psbase.GetMethodParameters("Create")
    $wmiMethodParameters.CommandLine = "test "
    $wmiMethodParameters.CurrentDirectory = "."
    $wmiMethodParameters.ProcessStartupInformation = $ai
    $pInfoCreate = $wmiclass.psbase.InvokeMethod("Create",$wmiMethodParameters,$null);
    $tempId = $pInfoCreate.ProcessId
    $pInfoObject = get-WmiObject -query "select * from win32_process where processid=$tempId"

0 个答案:

没有答案