Share via


Session.Invoke 메서드

메서드를 호출하고 메서드 호출 결과를 반환합니다.

구문

Session.Invoke( _
  ByVal actionUri, _
  ByVal resourceUri, _
  ByVal parameters, _
  [ ByVal flags ] _
)

매개 변수

actionUri [in]

호출할 메서드의 URI입니다.

resourceUri [in]

검색할 리소스의 식별자입니다.

이 매개 변수는 다음 중 하나를 포함할 수 있습니다.

parameters [in]

메서드에 대한 입력의 XML 표현입니다. 이 문자열을 제공해야 합니다. 그렇지 않으면 이 메서드가 실패합니다.

flags [in, optional]

예약되어 있습니다. 0으로 설정해야 합니다.

반환 값

메서드 출력의 XML 표현입니다.

예제

다음 VBScript 코드 예제에서는 Calc.exe 프로세스를 시작합니다. strInputParameters 매개 변수는 XML 형식의 입력 매개 변수를 포함합니다. WMI Win32_Process 클래스의 Create 메서드에 필요한 유일한 입력 매개 변수는 실행할 명령줄입니다.

Set objWsman = CreateObject( "WSMan.Automation" )
If objWsman is Nothing Then
    WScript.Echo "Failed to create WSMAN Automation object"
    WScript.Quit
End If 

Set objSession = objWsman.CreateSession
If objSession is Nothing Then
    WScript.Echo "Failed to create WSMAN Session object"
    WScript.Quit
End If 

strResource = "http://schemas.microsoft.com/wbem/wsman/1/" & _
    "wmi/root/cimv2/Win32_Process"

strInputParameters = "<p:Create_INPUT " & _
    "xmlns:p=""http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Process"">" & _
    "<p:CommandLine>" & "calc.exe" & _
    "</p:CommandLine>" & _
    "</p:Create_INPUT>"

strOutputParameters = objSession.Invoke( "Create", _
    strResource, strInputParameters )

DisplayOutput( strOutputParameters )

'****************************************************
' Displays WinRM XML message using built-in XSL
'****************************************************
Sub DisplayOutput( strWinRMXml )
    Dim xmlFile, xslFile
    Set xmlFile = CreateObject( "MSXml2.DOMDocument.3.0" ) 
    Set xslFile = CreateObject( "MSXml2.DOMDocument.3.0" )
    xmlFile.LoadXml( strWinRMXml )
    xslFile.Load( "WsmTxt.xsl" )
    Wscript.Echo xmlFile.TransformNode( xslFile ) 
End Sub

다음 VBScript 코드 예제에서는 Session.Invoke 메서드를 호출하여 Win32_ServiceStopService 메서드를 실행합니다. StopService 메서드에는 입력 매개 변수가 없습니다. 그러나 Invoke 메서드에는 매개 변수 매개 변수 에 XML 문자열이 필요합니다.

Option Explicit

Dim objWsman
Dim objSession
Dim strResponse
Dim strActionURI
Dim strInputXml
Dim strResourceURI
Dim strMethodName

set objWsman = CreateObject("Wsman.Automation")
set objSession = objWsman.CreateSession
strResourceURI = "http://schemas.microsoft.com/wbem/wsman/1/"_
    & "wmi/root/cimv2/Win32_Service?Name=w32time"
strMethodName = "StopService"
strActionURI = strMethodName                                      

strInputXml = "<p:StopService_INPUT " _
    & "xmlns:p=""http://schemas.microsoft.com/wbem/wsman/1/"_
    & "wmi/root/cimv2/Win32_Service""/>"

strResponse = objSession.Invoke(strMethodName, strResourceURI, strInputXml)

call DisplayOutput(strResponse)
 
strMethodName = "StartService" 
strActionURI = strResourceURI & "/" & strMethodName  
strInputXml = "<p:StartService_INPUT " _
    & "xmlns:p=""http://schemas.microsoft.com/wbem/wsman/1/"_
    & "wmi/root/cimv2/Win32_Service""/>"
strResponse = objSession.Invoke(strMethodName, _
    strResourceURI, strInputXml)

call DisplayOutput(strResponse)

 
'****************************************************
' Displays WinRM XML message using built-in XSL
'****************************************************

Sub DisplayOutput( strWinRMXml )
    Dim xmlFile, xslFile
    Set xmlFile = CreateObject( "MSXml2.DOMDocument.3.0" )    
    Set xslFile = CreateObject( "MSXml2.DOMDocument.3.0" )
    xmlFile.LoadXml( strWinRMXml )
    xslFile.Load( "WsmTxt.xsl" )
    Wscript.Echo xmlFile.TransformNode( xslFile )           
End Sub

요구 사항

요구 사항
지원되는 최소 클라이언트
Windows Vista
지원되는 최소 서버
Windows Server 2008
헤더
WSManDisp.h
IDL
WSManDisp.idl
라이브러리
WSManDisp.tlb
DLL
WSMAuto.dll

추가 정보

세션