Share via


Creazione di oggetti InParameters

Un oggetto InParameters contiene l'elenco di parametri per i metodi del provider chiamanti quando si usa un tipo di chiamata ExecMethod . I metodi SWbemObject.ExecMethod_, SWbemObject.ExecMethodAsync_, SWbemServices.ExecMethod e SWbemServices.ExecMethodAsync richiedono tutti un oggetto InParameters .

La procedura seguente descrive come costruire un oggetto InParameters .

Per costruire il parametro objwbemInParams

  1. Connettersi a WMI.

  2. Ottenere la definizione della classe WMI che definisce il metodo da eseguire.

  3. Ottenere un oggetto InParameters specifico per il metodo di classe WMI da eseguire.

    Set objInParam = objShare.Methods_("Create"). _
        inParameters.SpawnInstance_()
    
  4. Impostare le proprietà dell'istanza su qualsiasi valore appropriato. Assicurarsi di assegnare valori alle proprietà chiave della classe WMI che contiene il metodo da eseguire.

    Ad esempio, se si vuole impostare un parametro di input denominato myinputparam sul valore "abc" in un'istanza di InParameters denominata "INST", il codice sarà simile al seguente.

    INST.Properties_.Add ("myinputparam").Value = "abc".
    
  5. Eseguire il metodo e ottenere lo stato restituito del metodo in esecuzione.

Nell'esempio di codice seguente viene illustrata la configurazione dell'oggetto InParameters per creare un nuovo oggetto WMI che rappresenta una condivisione. Per altre informazioni sull'oggetto OutParameters , vedere Analisi degli oggetti OutParameters. In questo esempio viene restituito un valore restituito corretto (0) se è presente una cartella denominata "Condividi" nel percorso "C:/Share". Questo esempio consente di condividere questa cartella con altri utenti.

' 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