Create Method of the Win32_Process Class

The CreateWMI class method creates a new process. A fully-qualified path must be specified in cases where the program to be launched is not in the search path of Winmgmt.exe. If the newly created process attempts to interact with objects on the target system without the appropriate access privileges, it is terminated without notification to this method.

For security reasons the Win32_Process.Create method cannot be used to start an interactive process remotely.

Windows 2000 Professional with SP2 and earlier, Windows NT, and Windows 98/95:  Win32_Process.Create can create an interactive process remotely.

Processes created with the Win32_Process.Create method are limited by the job object unless the CREATE_BREAKAWAY_FROM_JOB flag is specified. For more information, see Win32_ProcessStartup and __ProviderHostQuotaConfiguration.

Windows 2000:  The processes created with the Win32_Process.Create method are not limited by the job object.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

MOF
uint32 Create(
  [in]   string CommandLine,
  [in]   string CurrentDirectory,
  [in]   Win32_ProcessStartup ProcessStartupInformation,
  [out]  uint32 ProcessId
);

Parameters

CommandLine [in]

Command line to execute. The system adds a null character to the command line, trimming the string if necessary, to indicate which file was actually used.

CurrentDirectory [in]

Current drive and directory for the child process. The string requires that the current directory resolves to a known path. A user can specify an absolute path or a path relative to the current working directory. If this parameter is NULL, the new process will have the same path as the calling process. This option is provided primarily for shells that must start an application and specify the application's initial drive and working directory.

ProcessStartupInformation [in]

The startup configuration of a Windows process. For more information, see Win32_ProcessStartup.

ProcessId [out]

Global process identifier that can be used to identify a process. The value is valid from the time the process is created until the time the process is terminated.

Return Value

Returns a value of 0 (zero) if the process was successfully created, and any other number to indicate an error. Some of the possible return values are listed in the following table.

Return codeDescription
0

Successful Completion

2

Access Denied

3

Insufficient Privilege

8

Unknown failure

9

Path Not Found

21

Invalid Parameter

 

Remarks

You can create an instance of the Win32_ProcessStartup class to configure the process before calling this method.

Examples

For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.

For C++ code examples, see WMI C++ Application Examples.

The following VBScript code example creates a Notepad process on the local computer. Win32_ProcessStartup is used to configure the process settings.

Const SW_NORMAL = 1
strComputer = "."
strCommand = "Notepad.exe" 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

' Configure the Notepad process to show a window
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = SW_NORMAL

' Create Notepad process
Set objProcess = objWMIService.Get("Win32_Process")
intReturn = objProcess.Create _
    (strCommand, Null, objConfig, intProcessID)
If intReturn <> 0 Then
    Wscript.Echo "Process could not be created." & _
        vbNewLine & "Command line: " & strCommand & _
        vbNewLine & "Return value: " & intReturn
Else
    Wscript.Echo "Process created." & _
        vbNewLine & "Command line: " & strCommand & _
        vbNewLine & "Process ID: " & intProcessID
End If

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
MOFCimwin32.mof
DLLCimwin32.dll
Namespace\root\cimv2

See Also

Operating System Classes
Win32_Process

Send comments about this topic to Microsoft

Build date: 11/3/2009

Tags :


Community Content

satkay
Help with win32_process.create

Hello,

I need to run a batch script remotely, but when i am trying win32_process.create i am getting error code 3 "insufficient previleges"

However i am able to get info like disk space and others.

Thanks in advance.


Stanley Roark
Out-of-memory error when creating a process with win32_process.create

For a kiosk-presentation developed in Adobe Director, I use a combination of a VBScript and some registry settings to execute the presentation as a custom shell. This is described in another article here on MSDN. The registry is changed to run "wscript myshell.vbs /nologo /b" instead of Windows Explorer. In the VBScript I create a process. The problem I have is that the Director Application returns an error ("Out of Memory, unable to create offscreen buffer") when booted like this. It is running fine when launched directly. Can anyone tell me why this may happen and if there are additional commands that could prevent this?

[Noelle Mallory - MSFT] Please post questions to the MSDN Forums at http://forums.microsoft.com/msdn. You will likely get a quicker response through the forum than through the Community Content.


Thomas Lee
Error 3, Insufficient Privilege - Win32_Process.Create

I have a VBScript which creates directories on the remote machines (Win XP & Win2k Pro) and copies few files, the script fails to execute on certain machines but runs fine on others.

Also the script fails to launch a Batch program on the remote machine with the same error.

Any help would be highly appreciated..

strComputer = "USDT923077"
 
   Set objFSO = CreateObject("Scripting.FileSystemObject")
	
   Set objWMIService = GetObject("winmgmts:" & _
		"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")
 
   errReturn = objWMIService.Create("cmd.exe /c md C:\WINNT\Temp\AvTmp", Null, Null, intProcessID)
 
 
   If errReturn <> 0 Then
 
	Wscript.Echo "Cannot create Tmp directory on: " & strComputer & " Error Code: " & errReturn
 
	Wscript.quit
		
   Else
			
        Wscript.sleep 5000
 
        objFSO.CopyFile "C:\AV_Removal_Tool\Removal_Tools\*.*", "\\" & strComputer & "\C$\WINNT\Temp\AvTmp", OverwriteExisting
 
   End If
Tags :

Stanley Roark
set outputstream
Hi, I try to call a remote process and get its command line out put.
I found that in C# there is a class Process can do this but only on local processes:

Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
string strRst = myProcess.StandardOutput.ReadToEnd();

How can I do the same thing at a remote process?

Thx!

DotNetIsFun
Fix For Out-of-memory error when creating a process with win32_process.create

Dim objServices : set objServices = GetObject("winmgmts:root\cimv2")
Dim objStartup : Set objStartup = objServices.Get("Win32_ProcessStartup")
Dim objConfig : Set objConfig = objStartup.SpawnInstance_ ' Object ref
Dim intProcessID


objConfig.CreateFlags = 16777216 ' process not to be limited by the job object.
intRetVal = objProcess.Create("Execute Command",,objConfig,intProcessID)


Page view tracker