Get Remote machine OS Version by querying Active Directory
Hi All,
Recently I had a requirement to find out the OS Version of remote machine but RPC calling were blocked in all machines due to security reasons. So I had to find another way.
I achieved this task simply by querying our organisation Active Directory by computer name. I have copied the method I used to achieve this task.
public string GetOSVersion(string computername)
{
DirectoryEntry deRoot;
string RootPath;
RootPath = ConfigurationManager.AppSettings["ADPath"];
deRoot = new DirectoryEntry(ConfigurationManager.AppSettings["ADPath"],
ConfigurationManager.AppSettings["ADUsername"],
ConfigurationManager.AppSettings["ADPassword"]);
deRoot.Path = RootPath;
DirectorySearcher ds = new DirectorySearcher(deRoot);
string strComputername = string.IsNullOrEmpty(computername) ? "" : "(cn=" + computername + ")";
ds.Filter = "(&(objectClass=Computer)" + strComputername + ")";
ds.SearchScope = SearchScope.Subtree;
SearchResult results = ds.FindOne();
deRoot.Close();
if (results == null)
{
return "";
}
else
{
return results.Properties["operatingSystem"][0].ToString() + results.Properties["operatingSystemVersion"][0].ToString();
}
}
Comments
Post a Comment