8 out of 18 rated this helpful - Rate this topic

Create method of the Win32_Process Class

Applies to: desktop apps only

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

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

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 client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Namespace

\root\CIMV2

MOF

Cimwin32.mof

DLL

Cimwin32.dll

See also

Operating System Classes
Win32_Process

 

 

Send comments about this topic to Microsoft

Build date: 3/9/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
CurrentDirectory Is Broken
Don't waste your time with ManagementBaseObject("CurrentDirectory") -- it's broken for UNC paths.

This fails miserably, with a "Path Not Found" error:

Dim mgmtInParams As ManagementBaseObject = mgmtClass.GetMethodParameters("Create")
mgmtInParams("CommandLine") = "notepad.exe"
mgmtInParams("CurrentDirectory") = "\\YOURSERVERNAME\YOURDRIVE\Windows"

Just ignore "CurrentDirectory" and put everything in the "CommandLine" parameter:

Dim mgmtInParams As ManagementBaseObject = mgmtClass.GetMethodParameters("Create")
mgmtInParams("CommandLine") = "\\YOURSERVERNAME\YOURDRIVE\Windows\notepad.exe"

Y'know it would REALLY HELP if Microsoft would supply WORKING EXAMPLES for *at least* the most commonly requested operations -- like launching an application on a remote server.
Wmi commands in DOS .bat formate
:Script1 @echo OFF color 1F cls :Start1 echo º Sbryson Ä WMI Functions echo º 1. WMIC list available aliases echo º 2. WMIC Path Win32_NetworkAdapter echo º 3. WMIC Path Win32_Processor32_64 echo º 4. WMIC Path Win32_Hardware info echo º 5. WMIC Path Win32_LoadPercentage echo º 6. WMIC Path Win32_DiskPartition echo º 7. WMIC Path Win32_Network\DNS echo º 8. WMIC Path Win32_Processid echo º 9. WMIC Process List echo º 10.WMIC workingsetsize echo º 11.WBEMTest.exe echo º 12. Return to Main Menu echo º 13. Exit echo Enter Choice. SET /P variable= IF %variable%==13 GOTO exit IF %variable%==12 GOTO menu IF %variable%==11 GOTO WBEMTest IF %variable%==10 GOTO workingsetsize IF %variable%==9 GOTO processsort IF %variable%==8 GOTO Processid IF %variable%==7 GOTO Network\DNS IF %variable%==6 GOTO DiskPartition IF %variable%==5 GOTO LoadPercentage IF %variable%==4 GOTO Hardware IF %variable%==3 GOTO Processor32_64 IF %variable%==2 GOTO NetworkAdapter IF %variable%==1 GOTO aliases :aliases @echo off color 1F cls SETLOCAL ENABLEDELAYEDEXPANSION FOR /F "skip=1 tokens=1,5" %%A IN ('WMIC /NameSpace:\\root\CLI Path MSFT_CliAlias Get FriendlyName^,Target ^| FIND "*"') DO SET Alias.%%A=%%B FOR /F "tokens=2,3 delims==." %%A IN ('SET Alias') DO ( SET "_Alias=%%A " SET _Alias=!_Alias:~0,20! ECHO !_Alias! = %%B ) ENDLOCAL echo. echo Export send to c:\centrada_scan\aliases.txt echo. SETLOCAL ENABLEDELAYEDEXPANSION FOR /F "skip=1 tokens=1,5" %%A IN ('WMIC /NameSpace:\\root\CLI Path MSFT_CliAlias Get FriendlyName^,Target ^| FIND "*"') DO SET Alias.%%A=%%B FOR /F "tokens=2,3 delims==." %%A IN ('SET Alias') DO ( SET "_Alias=%%A " SET _Alias=!_Alias:~0,20! ECHO !_Alias! = %%B ) >> c:\centrada_scan\aliases.txt ENDLOCAL start CMD.EXE cd\ Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :NetworkAdapter WMIC Path Win32_NetworkAdapter Where "PhysicalAdapter=TRUE" Get /Format:list echo. echo Export send to c:\centrada_scan\PhysicalAdapter.txt echo. WMIC Path Win32_NetworkAdapter Where "PhysicalAdapter=TRUE" Get /Format:list >> c:\centrada_scan\PhysicalAdapter.txt Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :Processor32_64 @ECHO OFF color 1F cls echo. WMIC Path Win32_Processor Get AddressWidth /Format:list echo. echo Export send to c:\centrada_scan\Processor32_64.txt echo. WMIC Path Win32_Processor Get AddressWidth /Format:list >> c:\centrada_scan\Processor32_64.txt echo. Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :Hardware @echo off color 1F cls echo Get Disk Drive Info echo. wmic diskdrive get name,size,model /Format:list echo. echo. echo Export send to c:\microsoft_scriptconsole\DiskDriveModel.txt echo. wmic diskdrive get name,size,model /Format:list >> c:\microsoft_scriptconsole\DiskDriveModel.txt echo. echo Press Enter to Get Disk Drive manufacturer pause > nul Echo. Echo Get Vendor Data echo. wmic csproduct get name,vendor,identifyingNumber /Format:list echo. echo. echo Export send to c:\microsoft_scriptconsole\vendor.txt echo. wmic csproduct get name,vendor,identifyingNumber /Format:list >> c:\microsoft_scriptconsole\vendor.txt echo. echo Press Enter to Get Bios Data pause > nul echo. echo Get Bios Data echo. wmic bios get name,serialnumber,version echo. echo Export send to c:\microsoft_scriptconsole\BiosData.txt echo. wmic bios get name,serialnumber,version >> c:\microsoft_scriptconsole\BiosData.txt echo. echo Press Enter to Get TotalPhysicalMemory pause > nul echo. echo Get TotalPhysicalMemory wmic COMPUTERSYSTEM get TotalPhysicalMemory,caption /Format:list echo. echo. echo Export send to c:\microsoft_scriptconsole\TotalPhysicalMemory.txt echo. wmic COMPUTERSYSTEM get TotalPhysicalMemory,caption /Format:list >> c:\microsoft_scriptconsole\TotalPhysicalMemory.txt echo. Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :LoadPercentage @echo off color 1F cls echo. echo Get CPU Load Percentage WMIC Path Win32_Processor Get LoadPercentage /Format:LIST echo. echo Export send to c:\centrada_scan\LoadPercentage.txt echo. WMIC Path Win32_Processor Get LoadPercentage /Format:LIST >> c:\centrada_scan\LoadPercentage.txt echo. Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :DiskPartition @echo off color 1F cls echo Get DiskPartition echo. WMIC Path Win32_DiskPartition Where "BootPartition=true And PrimaryPartition=true" Get DeviceID /Format:list echo. echo. echo Export send to c:\centrada_scan\DiskPartition.txt echo. WMIC Path Win32_DiskPartition Where "BootPartition=true And PrimaryPartition=true" Get DeviceID /Format:list >> c:\centrada_scan\DiskPartition.txt echo. echo Press Enter to Get LogicalDiskToPartition pause > nul echo Get LogicalDiskToPartition echo. WMIC Path Win32_LogicalDiskToPartition Get Antecedent^,Dependent /Format:list echo. echo. echo Export send to c:\centrada_scan\LogicalDiskToPartition.txt echo. WMIC Path Win32_LogicalDiskToPartition Get Antecedent^,Dependent /Format:list >> c:\centrada_scan\LogicalDiskToPartition.txt echo. Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :Network\DNS @echo off color 1F cls echo Get DNSHostName echo. WMIC Path Win32_NetworkAdapterConfiguration Get Description^,DNSHostName^,DNSServerSearchOrder /Format:list echo. echo. echo Export send to c:\centrada_scan\DNSHostName.txt echo. WMIC Path Win32_NetworkAdapterConfiguration Get Description^,DNSHostName^,DNSServerSearchOrder /Format:list >> c:\centrada_scan\DNSHostName.txt echo. Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :Processid @echo off color 1F cls echo. WMIC Path Win32_process get Caption,Processid,Commandline /Format:list echo. echo. echo Export send to c:\centrada_scan\Processid.txt Echo. WMIC Path Win32_process get Caption,Processid,Commandline /Format:list >> c:\centrada_scan\Processid.txt echo. Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :processsort @echo off color 1F cls echo. WMIC Path Win32_process | sort echo. echo. echo Export send to c:\centrada_scan\processsort.txt echo. echo Set to Excel Import Format echo. WMIC Path Win32_process | sort >> c:\centrada_scan\processsort.txt Echo. echo. Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :workingsetsize @echo off color 1F cls echo. wmic process get workingsetsize,commandline /format:list echo. echo Export send to c:\centrada_scan\workingsetsize.txt echo. wmic process get workingsetsize,commandline /format:list >> c:\centrada_scan\workingsetsize.txt echo. Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :WBEMTest @echo off color 1F cls echo. Start /wait WBEMTest.exe echo. Echo Completed... ECHO. echo Press Enter to go to WMIC menu echo. pause > nul goto start1 :menu Echo Completed... ECHO. echo Press Enter to go to menu echo. pause > nul goto menu :exit Echo Completed... ECHO. echo Press Enter to go to menu echo. pause > nul goto menu
Failed To Enable SE_BACKUP_PRIVILEGE

Installing Windows Installer Packages (msiexec.exe, setup.exe, or update.exe) using Win32_Process.Create can result in the following errors if done incorrectly:

ERROR_INSTALL_FAILURE 1603 Fatal error during installation.
Failed To Enable SE_BACKUP_PRIVILEGE
Failed To Enable SE_RESTORE_PRIVILEGE


Privileges are enabled by the Windows Installer process using the Win32 API function AdjustTokenPrivileges. Create the process so that the required privileges can be enabled by Windows Installer or any other process created. These errors were returned during an installation of the Microsoft .NET Framework 3.5 Service Pack 1, specifically, the Windows Imaging Component (dd_WIC.txt) and the XML Paper Specification (XPS) Shared Components Pack 1.0 (dd_XPS.txt).


Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")


The required privileges cannot be enabled by the created process:
SeAssignPrimaryTokenPrivilege: ERROR_NOT_ALL_ASSIGNED
SeAuditPrivilege: ERROR_NOT_ALL_ASSIGNED
SeBackupPrivilege: ERROR_NOT_ALL_ASSIGNED
SeChangeNotifyPrivilege : True
SeCreateGlobalPrivilege : True
SeCreatePagefilePrivilege: ERROR_NOT_ALL_ASSIGNED
SeCreatePermanentPrivilege: ERROR_NOT_ALL_ASSIGNED
SeCreateSymbolicLinkPrivilege: ERROR_NO_SUCH_PRIVILEGE
SeCreateTokenPrivilege: ERROR_NOT_ALL_ASSIGNED
SeDebugPrivilege: ERROR_NOT_ALL_ASSIGNED
SeEnableDelegationPrivilege: ERROR_NOT_ALL_ASSIGNED
SeImpersonatePrivilege : True
SeIncreaseBasePriorityPrivilege: ERROR_NOT_ALL_ASSIGNED
SeIncreaseQuotaPrivilege: ERROR_NOT_ALL_ASSIGNED
SeIncreaseWorkingSetPrivilege: ERROR_NO_SUCH_PRIVILEGE
SeLoadDriverPrivilege : True
SeLockMemoryPrivilege: ERROR_NOT_ALL_ASSIGNED
SeMachineAccountPrivilege: ERROR_NOT_ALL_ASSIGNED
SeManageVolumePrivilege: ERROR_NOT_ALL_ASSIGNED
SeProfileSingleProcessPrivilege: ERROR_NOT_ALL_ASSIGNED
SeRelabelPrivilege: ERROR_NO_SUCH_PRIVILEGE
SeRemoteShutdownPrivilege: ERROR_NOT_ALL_ASSIGNED
SeRestorePrivilege: ERROR_NOT_ALL_ASSIGNED
SeSecurityPrivilege: ERROR_NOT_ALL_ASSIGNED
SeShutdownPrivilege: ERROR_NOT_ALL_ASSIGNED
SeSyncAgentPrivilege: ERROR_NOT_ALL_ASSIGNED
SeSystemEnvironmentPrivilege: ERROR_NOT_ALL_ASSIGNED
SeSystemProfilePrivilege: ERROR_NOT_ALL_ASSIGNED
SeSystemtimePrivilege: ERROR_NOT_ALL_ASSIGNED
SeTakeOwnershipPrivilege: ERROR_NOT_ALL_ASSIGNED
SeTcbPrivilege: ERROR_NOT_ALL_ASSIGNED
SeTimeZonePrivilege: ERROR_NO_SUCH_PRIVILEGE
SeTrustedCredManAccessPrivilege: ERROR_NO_SUCH_PRIVILEGE
SeUndockPrivilege : True
SeUnsolicitedInputPrivilege: ERROR_NO_SUCH_PRIVILEGE




Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objProcess = GetObject("winmgmts:{(Backup, CreatePagefile, Debug, IncreaseBasePriority, LoadDriver, RemoteShutdown, Restore, Security, Shutdown, SystemEnvironment, SystemProfile, SystemTime, TakeOwnership, Undock)}!\\.\root\cimv2:Win32_Process")

Or

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")

objProcess.Security_.Privileges.AddAsString "SeBackupPrivilege"
objProcess.Security_.Privileges.AddAsString "SeCreatePagefilePrivilege"
objProcess.Security_.Privileges.AddAsString "SeDebugPrivilege"
objProcess.Security_.Privileges.AddAsString "SeIncreaseBasePriorityPrivilege"
objProcess.Security_.Privileges.AddAsString "SeLoadDriverPrivilege"
objProcess.Security_.Privileges.AddAsString "SeRemoteShutdownPrivilege"
objProcess.Security_.Privileges.AddAsString "SeRestorePrivilege"
objProcess.Security_.Privileges.AddAsString "SeSecurityPrivilege"
objProcess.Security_.Privileges.AddAsString "SeShutdownPrivilege"
objProcess.Security_.Privileges.AddAsString "SeSystemEnvironmentPrivilege"
objProcess.Security_.Privileges.AddAsString "SeSystemProfilePrivilege"
objProcess.Security_.Privileges.AddAsString "SeSystemTimePrivilege"
objProcess.Security_.Privileges.AddAsString "SeTakeOwnershipPrivilege"
objProcess.Security_.Privileges.AddAsString "SeUndockPrivilege"



Allows the process to enable the required privileges:
SeAssignPrimaryTokenPrivilege: ERROR_NOT_ALL_ASSIGNED
SeAuditPrivilege: ERROR_NOT_ALL_ASSIGNED
SeBackupPrivilege : True
SeChangeNotifyPrivilege : True
SeCreateGlobalPrivilege : True
SeCreatePagefilePrivilege : True
SeCreatePermanentPrivilege: ERROR_NOT_ALL_ASSIGNED
SeCreateSymbolicLinkPrivilege: ERROR_NO_SUCH_PRIVILEGE
SeCreateTokenPrivilege: ERROR_NOT_ALL_ASSIGNED
SeDebugPrivilege : True
SeEnableDelegationPrivilege: ERROR_NOT_ALL_ASSIGNED
SeImpersonatePrivilege : True
SeIncreaseBasePriorityPrivilege : True
SeIncreaseQuotaPrivilege: ERROR_NOT_ALL_ASSIGNED
SeIncreaseWorkingSetPrivilege: ERROR_NO_SUCH_PRIVILEGE
SeLoadDriverPrivilege : True
SeLockMemoryPrivilege: ERROR_NOT_ALL_ASSIGNED
SeMachineAccountPrivilege: ERROR_NOT_ALL_ASSIGNED
SeManageVolumePrivilege: ERROR_NOT_ALL_ASSIGNED
SeProfileSingleProcessPrivilege: ERROR_NOT_ALL_ASSIGNED
SeRelabelPrivilege: ERROR_NO_SUCH_PRIVILEGE
SeRemoteShutdownPrivilege : True
SeRestorePrivilege : True
SeSecurityPrivilege : True
SeShutdownPrivilege : True
SeSyncAgentPrivilege: ERROR_NOT_ALL_ASSIGNED
SeSystemEnvironmentPrivilege : True
SeSystemProfilePrivilege : True
SeSystemtimePrivilege : True
SeTakeOwnershipPrivilege : True
SeTcbPrivilege: ERROR_NOT_ALL_ASSIGNED
SeTimeZonePrivilege: ERROR_NO_SUCH_PRIVILEGE
SeTrustedCredManAccessPrivilege: ERROR_NO_SUCH_PRIVILEGE
SeUndockPrivilege : True
SeUnsolicitedInputPrivilege: ERROR_NO_SUCH_PRIVILEGE

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)

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!
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.

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
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.