Creating instances

The arguments for Win32_Process.Create include a ProcessStartupInformation parameter. The ProcessStartupInformation is described by a WMI class, Win32_ProcessStartup.

There are no existing instances of Win32_ProcessStartup (Get-CimInstance), and the class does not have a Create method (or any other constructor).

New-CimInstance can be used to create a class:

$class = Get-CimClass Win32_ProcessStartup 
$startupInfo = New-CimInstance -CimClass $class -ClientOnly 

New-Object can also be used:

$class = Get-CimClass Win32_ProcessStartup 
$startupInfo = New-Object CimInstance $class 

Properties may be set on the created instance; the effect of each property is documented on the MSDN:

https://msdn.microsoft.com/en-us/library/aa394375(v=vs.85).aspx

In the following example, properties are set to dictate the position and title of a cmd.exe window:

$class = Get-CimClass Win32_ProcessStartup 
$startupInfo = New-CimInstance -CimClass $class -ClientOnly 
$startupInfo.X = 50 
$startupInfo.Y = 50 
$startupInfo.Title = 'This is the window title' 
 
$argumentList = @{ 
    CommandLine = 'cmd.exe' 
    ProcessStartupInformation = $startupInfo 
} 
$returnObject = Invoke-CimMethod Win32_Process -MethodName Create -Arguments $argumentList 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.220.16