SWbemServices.ExecMethod 메서드

SWbemServices 개체의 ExecMethod 메서드는 메서드 공급자가 내보낸 메서드를 실행합니다. 이 메서드는 적절한 공급자에게 전달되는 메서드가 실행되는 동안 차단됩니다. 그러면 정보와 상태가 반환됩니다. WMI가 아닌 공급자가 메서드를 구현합니다.

이 메서드는 동기 모드에서 호출됩니다. 자세한 내용은 메서드 호출을 참조하세요.

이 구문에 대한 설명은 스크립팅 API의 문서 규칙을 참조하세요.

구문

objOutParams = .ExecMethod( _
  ByVal strObjectPath, _
  ByVal strMethodName, _
  [ ByVal objWbemInParams ], _
  [ ByVal iFlags ], _
  [ ByVal objWbemNamedValueSet ] _
)

매개 변수

strObjectPath

필수 요소. 메서드가 실행되는 개체의 개체 경로를 포함하는 문자열입니다. 자세한 내용은 WMI 개체의 위치 설명을 참조하세요.

strMethodName

필수 요소. 개체의 메서드 이름입니다.

objWbemInParams [선택 사항]

실행 중인 메서드에 대한 입력 매개 변수가 포함된 SWbemObject 개체입니다. 기본적으로 이 매개 변수는 정의되지 않습니다. 자세한 내용은 InParameters 개체 생성 및 OutParameters 개체 구문 분석을 참조하세요.

iFlags [선택 사항]

예약되어 있습니다. 이 값은 0이어야 합니다.

objWbemNamedValueSet [optional]

일반적으로 이는 정의되지 않습니다. 그렇지 않으면 요청을 서비스하는 공급자가 사용할 수 있는 컨텍스트 정보를 나타내는 요소가 있는 SWbemNamedValueSet 개체입니다. 그러한 정보를 지원하거나 요구하는 공급자는 인식된 값 이름, 값의 데이터 형식, 허용된 값 및 의미 체계를 문서화해야 합니다.

반환 값

메서드가 성공하면 SWbemObject 개체가 반환됩니다. 반환된 개체에는 실행 중인 메서드에 대한 out 매개 변수와 반환 값이 포함됩니다.

오류 코드

ExecMethod 메서드가 완료된 후 Err 개체에는 다음 목록에 있는 오류 코드 중 하나가 포함될 수 있습니다.

wbemErrFailed - 2147749889(0x80041001)

알 수 없는 오류입니다.

wbemErrInvalidClass - 2147749904(0x80041010)

지정된 클래스가 잘못되었습니다.

wbemErrInvalidParameter - 2147749896(0x80041008)

지정된 매개 변수가 잘못되었습니다.

wbemErrOutOfMemory - 2147749894(0x80041006)

메모리가 부족하여 작업을 완료할 수 없습니다.

wbemErrInvalidMethod - 2147749934(0x8004102E)

요청한 방법을 사용할 수 없습니다.

wbemErrAccessDenied - 2147749891(0x80041003)

현재 사용자는 메서드를 실행할 권한이 없습니다.

설명

메서드를 직접 실행할 수 없는 경우 공급자 메서드를 실행하기 위한 직접 액세스 대신 SWbemServices.ExecMethod를 사용합니다. ExecMethod 메서드를 사용하면 공급자가 제공하는 경우 출력 매개 변수를 지원하지 않는 스크립트 언어로 출력 매개 변수를 가져올 수 있습니다. 그렇지 않으면 메서드를 호출하는 권장 방법은 직접 액세스를 사용하는 것입니다. 자세한 내용은 클래스 및 인스턴스 정보 조작을 참조하세요.

예를 들어, Win32_Service에서 StartService 공급자 메서드를 호출하는 다음 코드 예는 직접 액세스를 사용합니다.

oService = GetObject("winmgmts:Win32_Service=Alerter")
iStatus = oService.StartService()

이 예에서는 SWbemServices.ExecMethod를 호출하여 StartService 메서드를 실행합니다. SWbemObject.ExecMethod와 달리 SWbemServices.ExecMethod가 이미 개체에서 작동하지 않기 때문에 개체 경로가 필요합니다.

Set WbemServices = GetObject("winmgmts:")
Set oService = GetObject("winmgmts:Win32_Service='Alerter'")
Set oPath = GetObject("winmgmts:Win32_Service='Alerter'").Path_
WbemServices.ExecMethod oPath, "StartService"

SWbemServices.ExecMethod 메서드에는 개체 경로가 필요합니다. 스크립트에 이미 SWbemObject 개체가 있는 경우 SWbemObject.ExecMethod 메서드를 사용합니다.

예제

다음 예에서는 ExecMethod 메서드를 보여 줍니다. 이 스크립트는 메모장을 실행 중인 프로세스를 나타내는 Win32_Process 개체를 만듭니다. InParameters 개체의 설정과 OutParameters 개체에서 결과를 얻는 방법을 보여 줍니다. 비동기적으로 수행되는 동일한 작업을 보여 주는 스크립트는 SWbemServices.ExecMethodAsync를 참조하세요. 직접 액세스를 사용하는 예는 Win32_Process 클래스의 메서드 만들기를 참조하세요. SWbemObject를 사용하는 동일한 작업의 예는 SWbemObject.ExecMethod를 참조하세요.

' Connect to WMI
set Services = getobject("winmgmts:root\cimv2")

' Obtain the class definition object of a Win32_Process object.
Set oProcess = Services.Get("Win32_Process")

' Create the SWbemMethod.InParameters object
' to hold the input parameter needed
' for the Win32_Process.Create method call.
' The oProcess.Methods_("Create") call
' obtains obtains a class object that
' defines the correct input parameters
' for the Win32_Process.Create call.
' The InParameters object is an 
' SWbemObject object so SWbemObject.SpawnInstance_ 
'can be called to create it.

Set oInParams = _
    oProcess.Methods_("Create").InParameters.SpawnInstance_
oInParams.CommandLine = "Notepad.exe"

'Call SWbemServices.ExecMethod with the WMI path Win32_Process
Set oOutParams = _
    Services.ExecMethod( "Win32_Process", "Create", oInParams)

If oOutParams.ReturnValue = 0 Then
    wscript.echo "Create method executed successfully."
Else
' If the Create method failed to execute,
' an empty OutParameters object is returned. 
    If IsNull(oOutParams.ReturnValue) Then
        wscript.echo "Create method failed to execute."  
    Else
        wscript.echo "Create method executed" _
            & " but had error " _
            & "0x" & hex(oOutParams.ReturnValue)
    End If
End If

요구 사항

요구 사항
지원되는 최소 클라이언트
Windows Vista
지원되는 최소 서버
Windows Server 2008
헤더
Wbemdisp.h
유형 라이브러리
Wbemdisp.tlb
DLL
Wbemdisp.dll
CLSID
CLSID_SWbemServices
IID
IID_ISWbemServices

추가 정보

SWbemServices

SWbemObject.ExecMethod_

공급자 메서드 호출

클래스 및 인스턴스 정보 조작