Win32_Process 클래스의 메서드 만들기

WMI 클래스 만들기 메서드는 새 프로세스를 만듭니다.

이 항목에서는 MOF(Managed Object Format) 구문을 사용합니다. 이 메서드를 사용하는 방법에 대한 자세한 내용은 메서드 호출을 참조하세요.

구문

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

매개 변수

CommandLine [in]

실행할 명령줄입니다. 시스템은 명령줄에 null 문자를 추가하여 필요한 경우 문자열을 트리밍하여 실제로 사용된 파일을 나타냅니다.

CurrentDirectory [in]

자식 프로세스의 현재 드라이브 및 디렉터리입니다. 문자열을 사용하려면 현재 디렉터리가 알려진 경로로 확인되어야 합니다. 사용자는 현재 작업 디렉터리를 기준으로 절대 경로 또는 경로를 지정할 수 있습니다. 이 매개 변수가 NULL이면 새 프로세스는 호출 프로세스와 동일한 경로를 갖습니다. 이 옵션은 주로 애플리케이션을 시작하고 애플리케이션의 초기 드라이브 및 작업 디렉터리를 지정해야 하는 셸에 대해 제공됩니다.

ProcessStartupInformation [in]

Windows 프로세스의 시작 구성입니다. 자세한 내용은 Win32_ProcessStartup 참조하세요.

ProcessId [out]

프로세스를 식별하는 데 사용할 수 있는 전역 프로세스 식별자입니다. 이 값은 프로세스가 만들어지는 시점부터 프로세스가 종료될 때까지 유효합니다.

반환 값

프로세스가 성공적으로 만들어진 경우 값 0을 반환하고 오류를 나타내는 다른 숫자를 반환합니다. 추가 오류 코드는 WMI 오류 상수 또는 WbemErrorEnum을 참조하세요. 일반적인 HRESULT 값은시스템 오류 코드를 참조하세요.

성공적인 완료 (0)

액세스 거부됨 (2)

권한 부족 (3)

알 수 없는 오류 (8)

경로를 찾을 수 없음 (9)

잘못된 매개 변수 (21)

기타 (22개 4294967295)

설명

이 메서드를 호출하기 전에 Win32_ProcessStartup 클래스의 instance 만들어 프로세스를 구성할 수 있습니다.

실행할 프로그램이 Winmgmt.exe 검색 경로에 없는 경우 정규화된 경로를 지정해야 합니다. 새로 만든 프로세스가 적절한 액세스 권한 없이 대상 시스템의 개체와 상호 작용하려고 하면 이 메서드에 대한 알림 없이 종료됩니다.

보안상의 이유로 Win32_Process.Create 메서드를 사용하여 대화형 프로세스를 원격으로 시작할 수 없습니다.

Win32_Process.Create 메서드를 사용하여 만든 프로세스는 CREATE_BREAKAWAY_FROM_JOB 플래그를 지정하지 않는 한 작업 개체에 의해 제한됩니다. 자세한 내용은 Win32_ProcessStartup__ProviderHostQuotaConfiguration 참조하세요.

예제

다음 VBScript 예제에서는 CIM 메서드를 SWbemObject의 자동화 메서드인 것처럼 호출하는 방법을 보여 줍니다.

on error resume next

set process = GetObject("winmgmts:Win32_Process")

result = process.Create ("notepad.exe",null,null,processid)

WScript.Echo "Method returned result = " & result
WScript.Echo "Id of new process is " & processid

if err <>0 then
 WScript.Echo Err.Description, "0x" & Hex(Err.Number)
end if

다음 Perl 예제에서는 SWbemObject의 자동화 메서드인 것처럼 CIM 메서드를 호출하는 방법을 보여 줍니다.

use strict;
use Win32::OLE;

my ($process, $outParam, $processid, $inParam, $objMethod);

eval { $process = 
 Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2:Win32_Process"); };

if (!$@ && defined $process)
{
 $objMethod = $process->Methods_("Create");

 #Spawn an instance of inParameters and assign the values.
 $inParam = $objMethod->inParameters->SpawnInstance_ if (defined $objMethod);
 $inParam->{CommandLine} = "notepad.exe";
 $inParam->{CurrentDirectory} = undef;
 $inParam->{ProcessStartupInformation} = undef;

 $outParam = $process->ExecMethod_("Create", $inParam) if (defined $inParam);
 if ($outParam->{ReturnValue})
 {
  print STDERR Win32::OLE->LastError, "\n";
 }
 else
 {
  print "Method returned result = $outParam->{ReturnValue}\n";
  print "Id of new process is $outParam->{ProcessId}\n"
 }
}
else
{
 print STDERR Win32::OLE->LastError, "\n";
}

다음 VBScript 코드 예제에서는 로컬 컴퓨터에 메모장 프로세스를 만듭니다. Win32_ProcessStartup 프로세스 설정을 구성하는 데 사용됩니다.

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

요구 사항

요구 사항
지원되는 최소 클라이언트
Windows Vista
지원되는 최소 서버
Windows Server 2008
네임스페이스
Root\CIMV2
MOF
CIMWin32.mof
DLL
CIMWin32.dll

추가 정보

운영 체제 클래스

Win32_Process

WMI 작업: 프로세스