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 クラスのキー プロパティに値を指定してください。

    たとえば、myinputparam という入力パラメータを、"INST" と呼ばれる InParameters のインスタンスの値 "abc" に設定する場合、コードは次のようになります。

    INST.Properties_.Add ("myinputparam").Value = "abc".
    
  5. メソッドを実行し、実行中のメソッドのリターン状態を取得します。

次のコード例は、InParameters オブジェクトを設定して、共有を表す新しい WMI オブジェクトを作成する方法を示しています。 OutParameters オブジェクトの詳細については、「OutParameters オブジェクトの解析」を参照してください。 この例では、"Share" というフォルダーが "C:/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