InParameters 개체 생성

InParameters 개체에는 ExecMethod 유형의 호출을 사용할 때 공급자 메서드를 호출하기 위한 매개 변수 목록이 포함되어 있습니다. SWbemObject.ExecMethod_, SWbemObject.ExecMethodAsync_, SWbemServices.ExecMethodSWbemServices.ExecMethodAsync 메서드는 모두 InParameters 개체를 요구합니다.

다음 절차에서는 InParameters 개체를 생성하는 방법을 설명합니다.

objwbemInParams 매개 변수를 생성하는 방법

  1. WMI에 연결합니다.

  2. 실행할 메서드를 정의하는 WMI 클래스의 정의를 가져옵니다.

  3. 실행하려는 WMI 클래스 메서드와 관련된 InParameters 개체를 가져옵니다.

    Set objInParam = objShare.Methods_("Create"). _
        inParameters.SpawnInstance_()
    
  4. 인스턴스의 속성을 적절한 값으로 설정합니다. 실행하려는 메서드가 포함된 WMI 클래스의 키 속성에 값을 제공해야 합니다.

    예를 들어 "INST"라는 InParameters 인스턴스에서 myinputparam이라는 입력 매개 변수를 "abc" 값으로 설정하려는 경우, 코드는 다음과 같습니다.

    INST.Properties_.Add ("myinputparam").Value = "abc".
    
  5. 메서드를 실행하고 실행 중인 메서드의 반환 상태를 가져옵니다.

다음 코드 예제에서는 공유를 나타내는 새 WMI 개체를 만들도록 InParameters 개체를 설정하는 방법을 확인할 수 있습니다. OutParameters 개체에 대한 자세한 내용은 OutParameters 개체 구문 분석을 참조하세요. 다음은 "C:/Share" 위치에 "Share"라는 폴더가 있는 경우 성공적인 반환 값(0)을 반환하는 예제입니다. 이 예제에서는 이 폴더를 다른 사용자와 공유할 수 있게 합니다.

' Connect to WMI.
Set objServices = GetObject("winmgmts:root\cimv2")

' Obtain the definition of the WMI class that defines
' the method you want to execute.
Set objShare = objServices.Get("Win32_Share")

' Obtain an InParameters object specific
' to the WMI class method you want to execute.
Set objInParam = objShare.Methods_("Create"). _
    inParameters.SpawnInstance_()

' Set the properties of the instance to whatever
' values are appropriate.
objInParam.Properties_.Item("Access") = objSecDescriptor
objInParam.Properties_.Item("Description") = _
    "New share created by WMI script"
objInParam.Properties_.Item("Name") = "share"
objInParam.Properties_.Item("Path") = "C:\share"
objInParam.Properties_.Item("Type") = 0
'optional - default is 'max allowed'
objInParam.Properties_.Item("MaximumAllowed") = 100
'optional - default is no password
objInParam.Properties_.Item("Password") = "Password"

' Execute the method and obtain the return status. 
' The OutParameters object in objOutParams
' is created by the provider. 
Set objOutParams = objShare.ExecMethod_("Create", objInParam)    
wscript.echo objOutParams.ReturnValue