Hi,
I have 7 computers and 5 controllers(no OS) connected to Domain controller.
when I used WMI to query for registry, it take a long time (about 60
minutes) to return the result. if it a controller then there is no WMI and
return a NULL ManagementClass. Does anyone know there is another way to make
it run faster?
protected static ManagementClass ConnectToConfigProv(string host, string
managementClass)
{
ManagementClass Config;
try
{
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
string sPath = "\\\\" + host + "\\root\\cimv2";
ManagementScope scope = new ManagementScope(sPath, options);
scope.Connect();
Config = new ManagementClass(
scope,
new ManagementPath(managementClass),
null);
}
catch
{
sErr = "WMI connection failed";
return Config=null;
//throw (new Exception(sErr));
}
return Config;
}
public string RemoteRegistryReadValue(string sServer)
{
ManagementClass ManageConfig;
string sValue = null;
string sErrMsg = null;
string mgmtPath = "Win32_OperatingSystem";
ManageConfig= ConnectToConfigProv(sServer, mgmtPath);
if (ManageConfig== null)
{
sErrMsg = "WMI connection to \"Win32_OperatingSystem\" of
computer " + sServer + " failed";
//throw (new Exception(sErrMsg));
}
else
{
sValue = "There is no WMI, must be controller";
}
return sValue;
}
thanks