共用方式為


建構 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 的輸入參數設定為 InParameters 實例中的值 “abc”, 稱為 “INST”,程式代碼看起來會像這樣。

    INST.Properties_.Add ("myinputparam").Value = "abc".
    
  5. 執行方法,並取得您正在執行之方法的傳回狀態。

下列程式代碼範例說明如何設定 InParameters 物件,以建立代表共用的新 WMI 物件。 如需 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