5
Sto cercando di leggere la chiave di registro utilizzando WMI. Ho provato con il seguente codice ma non riesco a ottenere il valore della chiave di registro.Lettura delle chiavi del Registro di sistema tramite WMI
Qualcuno può aiutarmi per quanto riguarda questo problema.
ConnectionOptions oConn = new ConnectionOptions();
System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\\" +hostname + @"\root\cimv2", oConn);
scope.Connect();
ManagementClass registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null);
ManagementBaseObject inParams = registry.GetMethodParameters("GetStringValue");
inParams["sSubKeyName"] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\.NETFramework";
inParams["sValueName"] = "InstallRoot";
ManagementBaseObject outParams = registry.InvokeMethod("GetStringValue", inParams, null);
if (outParams.Properties["sValue"].Value != null)
{
output = outParams.Properties["sValue"].Value.ToString();
}
Nota: Voglio leggere le chiavi di registro utilizzando solo WMI.
Quale risultato ottieni? Eccezione/errore, valore nullo o valore inatteso? – Marcus