Lalit said:
Thanks for the reply, I got a code from code project to read registry
values
using WMI.
I stunk on one more problem now. I was able to get version number of com
dll but I want to get version of .Net dll and for .Net dlls it return NULL
in Version property.
Any Idea?
Lalit
You need to use the StdRegProv class in WMI's root\default namespace.
Following snippet reads a DWORD value from HKCU to get you started. Consult
the WMI docs in MSDN for more details....
....
const uint HKEY_CURRENT_USER = 0x80000001;
ConnectionOptions co = new ConnectionOptions();
co.Username = "administrator"; // user with sufficient privs to read the
reg key
co.Password = "xxxxxxx"; // his pwd
string remMachine = "ssssss"; // remote machine name
ManagementPath p = new ManagementPath("StdRegProv");
ManagementScope scope = new ManagementScope(@"\\" + remMachine +
@"\root\default", co);
using (ManagementClass regClass = new ManagementClass(scope, p, null))
{
ManagementBaseObject inputArgs =
regClass.GetMethodParameters("GetDWORDValue");
inputArgs["hDefKey"] = HKEY_CURRENT_USER;
inputArgs["sSubKeyName"] = "Console";
inputArgs["sValueName"] = "HistoryBufferSize";
ManagementBaseObject outParams = regClass.InvokeMethod("GetDWORDValue",
inputArgs, null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret == 0)
Console.WriteLine("Success: {0}",
(uint)(outParams.Properties["uValue"].Value));
else Console.WriteLine("Failed with error code: {0}", ret);
}
....
Willy.