Share via


Impostazione della sicurezza in una chiamata asincrona in VBScript

Le prestazioni delle chiamate semisynchrono sono in genere adeguate per la maggior parte delle situazioni. Le chiamate asincrone non sono in genere una procedura consigliata per gli script. Tuttavia, se è necessario effettuare chiamate asincrone, è possibile impostare un valore del Registro di sistema per forzare WMI di eseguire controlli di accesso sulle chiamate asincrone.

Il valore del\ Registro di sistema HKEY_LOCAL_MACHINESoftware\Microsoft\WBEMCIMOM\\UnsecAppAccessControlDefault controlla se WMI verifica un livello di autenticazione accettabile quando restituisce dati per una chiamata asincrona. Il callback può essere restituito a un livello di autenticazione inferiore a quello della chiamata asincrona originale. Per impostazione predefinita, questo valore è impostato su zero in modo che i callback non vengano controllati. Per proteggere le chiamate asincrone nello scripting, è necessario impostare la chiave del Registro di sistema su 1 (una).

Gli script possono usare i metodi GetStringValue e SetStringValue dell'oggetto del Registro di sistema StdRegProv per modificare l'impostazione del valore del Registro di sistema UnsecAppAccessControlDefault. Per altre informazioni sui livelli di autenticazione e rappresentazione necessari per l'accesso remoto, vedere Connessione a WMI in un computer remoto.

Per impostare la sicurezza delle chiamate asincrone in VBScript

Nell'esempio di codice VBScript seguente viene illustrato come modificare il valore del Registro di sistema per controllare l'autenticazione WMI dei callback.

Lo script modifica il valore di UnsecAppAccessControlDefault da zero a uno o se il valore è già impostato, da uno a zero. Zero è il valore predefinito in un sistema appena installato. Dopo aver impostato il flag, l'impostazione persiste nel riavvio o nel riavvio WMI.

Lo script usa un oggetto SWbemMethod.InParameters e SWbemObject.ExecMethod per chiamare StdRegProv.GetStringValue e StdRegProv.SetStringValue. Per altre informazioni sull'impostazione dei valori in un oggetto InParameters , vedere Costruzione di oggetti InParameters e Analisi degli oggetti OutParameters. Per un esempio di chiamata del Registro di sistema tramite GetObject, vedere StdRegProv.SetStringValue.

' Registry key value in hex
Const hklm = &h800000002  
' Subkey string 
Const Subkey = "software\\microsoft\\wbem\\cimom" 
' Asynchronous access control
Const sValueName = "UnsecAppAccessControlDefault" 

' Obtain registry object
Set objReg = GetObject("winmgmts:root\default:StdRegProv") 

' Get the initial value of the asynchronous 
'   access control registry key
' Use an InParameters object to set up the 
'   parameters for the ExecMethod call
' For more information see Constructing InParameters Objects 
'   topic and SWbemObject.ExecMethod_ topic

Set InParams = objReg.methods_("GetStringValue").InParameters.SpawnInstance_
InParams.hDefKey = hklm
InParams.sSubKeyName = Subkey
InParams.sValueName = sValueName

' Get return value from OutParameters object returned by ExecMethod. 
' For more information see Parsing OutParameters Objects topic

Set OutParams = objReg.Execmethod_("GetStringValue",InParams)

If (OutParams.ReturnValue <> 0) then
   Wscript.Echo "GetStringValue returned " & OutParams.ReturnValue
   Wscript.Quit 1
End If

Svalue = OutParams.sValue
If (sValue = 0) Then
   AccessControl = "WMI not performing asynch access control"
Else 
   AccessControl = "WMI performing asynch access control"  
End If
Wscript.Echo sValueName & " = " _
    & sValue & VBNewLine & AccessControl

' Change asynchronous access control registry key value
Set InParams = objReg.methods_("SetStringValue").InParameters.SpawnInstance_

InParams.hDefKey = hklm
InParams.sSubKeyName = Subkey
InParams.sValueName = sValueName
InParams.sValue = sValue XOR 1

Set OutParams = objReg.ExecMethod_("SetStringValue",InParams)

If (OutParams.Returnvalue <> 0) Then
    Wscript.Echo "SetStringValue returned " & OutParams.Returnvalue
    Wscript.Quit 1
End If

Wscript.Echo SValueName & " changed to " & (sValue XOR 1)