网上关于WMI的资料很多,但一直没有比较全的属性介绍.今天通过反射把所有属性都给弄出来了.
关于WMI的代码就不多说了.
需要手动添加引用:System.Management
/// <summary>
/// 获取查询队列 ///
/// </summary>
/// <param name="ip"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="queryString"></param>
/// <returns></returns>
private static ManagementObjectCollection GetQueryObject(string ip, string username, string password, string queryString)
{
ConnectionOptions co = new ConnectionOptions();
string hostname = !string.IsNullOrEmpty(ip) ? NetManager.GetRemoteHostName(ip) : "";
co.Username = (string.IsNullOrEmpty(hostname)?"":hostname+ "\\" ) + username;
co.Password = password;
ManagementScope scm = string.IsNullOrEmpty(ip) || ip.Trim()=="" || ip.ToLower().Trim() == "localhost" || ip.ToLower().Trim() == "127.0.0.1" ?
new ManagementScope(@"\\localhost\root\cimv2"):new ManagementScope(@"\\" + ip + @"\root\cimv2", co);
/// 获取查询队列 ///
/// </summary>
/// <param name="ip"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="queryString"></param>
/// <returns></returns>
private static ManagementObjectCollection GetQueryObject(string ip, string username, string password, string queryString)
{
ConnectionOptions co = new ConnectionOptions();
string hostname = !string.IsNullOrEmpty(ip) ? NetManager.GetRemoteHostName(ip) : "";
co.Username = (string.IsNullOrEmpty(hostname)?"":hostname+ "\\" ) + username;
co.Password = password;
ManagementScope scm = string.IsNullOrEmpty(ip) || ip.Trim()=="" || ip.ToLower().Trim() == "localhost" || ip.ToLower().Trim() == "127.0.0.1" ?
new ManagementScope(@"\\localhost\root\cimv2"):new ManagementScope(@"\\" + ip + @"\root\cimv2", co);
ObjectQuery oq = new System.Management.ObjectQuery(queryString);
ManagementObjectSearcher query = new ManagementObjectSearcher(scm, oq);
return query.Get();
}
ManagementObjectSearcher query = new ManagementObjectSearcher(scm, oq);
return query.Get();
}
新增linux硬件信息获取
但linux主机获取不全面
欢迎提交linux硬件信息获取通用的shell命令
但linux主机获取不全面
欢迎提交linux硬件信息获取通用的shell命令
示例效果图如下:
C#利用开源项目SharpSsh远程执行linux的shell命令源码
远程操作linux请看另一篇:
http://www.jm47.com/project/1213