Costruzione di oggetti InParameters
Un oggetto InParameters contiene l'elenco di parametri per chiamare i metodi del provider quando si usa un ExecMethod tipo di chiamata. I metodi SWbemObject.ExecMethod_, SWbemObject.ExecMethodAsync_, SWbemServices.ExecMethode SWbemServices.ExecMethodAsync richiedono tutti un oggetto InParameters.
Nella procedura seguente viene descritto come costruire un oggetto InParameters.
Per costruire il parametro objwbemInParams
Connettersi a WMI.
Ottenere la definizione della classe WMI che definisce il metodo da eseguire.
Ottieni un oggetto InParameters specifico al metodo della classe WMI che si desidera eseguire.
Set objInParam = objShare.Methods_("Create"). _ inParameters.SpawnInstance_()
Impostare le proprietà dell'istanza sui valori più appropriati. Assicurarsi di assegnare valori alle proprietà della chiave nella 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 denominato "INST", il codice sarà simile al seguente.
INST.Properties_.Add ("myinputparam").Value = "abc".
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 ulteriori 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