2013-06-04 21 views
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.

+1

Quale risultato ottieni? Eccezione/errore, valore nullo o valore inatteso? – Marcus

risposta

3

È necessario impostare il valore del parametro hDefKey (hive) e rimuovere l'hive dal parametro sSubKeyName.

inParams["hDefKey"] =0x80000002;// HKEY_LOCAL_MACHINE; 
inParams["sSubKeyName"] = "SOFTWARE\\Microsoft\\.NETFramework"; 
Problemi correlati