using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.IO;
using System.Net.Security;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
using System.Diagnostics;
using System.Management; namespace DemoCodeTester
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} string getWMIResult(string sql)
{
try
{
var sb = new StringBuilder();
var index = ; ManagementObjectSearcher searcher = new ManagementObjectSearcher(sql);
ManagementObjectCollection objects = searcher.Get();
foreach (ManagementObject obj in objects)
{
sb.Append(index++.ToString() + ".*****************************************************").AppendLine(); try
{
var properties = obj.Properties.Cast<PropertyData>();
foreach (var p in properties)
{
if (p.Value != null)
sb.AppendFormat("{0}:{1}", p.Name, p.Value).AppendLine();
}
}
catch
{ }
} return sb.ToString();
}
catch(Exception ex)
{
return ex.ToString();
}
finally
{ }
} private void Form1_Load(object sender, EventArgs e)
{ } private void btnExecute_Click(object sender, EventArgs e)
{
var result = getWMIResult(txtWMI.Text);
txtResult.Text = result;
}
}
}
namespace DemoCodeTester
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnExecute = new System.Windows.Forms.Button();
this.txtResult = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.txtWMI = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btnExecute
//
this.btnExecute.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnExecute.Location = new System.Drawing.Point(, );
this.btnExecute.Name = "btnExecute";
this.btnExecute.Size = new System.Drawing.Size(, );
this.btnExecute.TabIndex = ;
this.btnExecute.Text = "Execute";
this.btnExecute.UseVisualStyleBackColor = true;
this.btnExecute.Click += new System.EventHandler(this.btnExecute_Click);
//
// txtResult
//
this.txtResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtResult.Location = new System.Drawing.Point(, );
this.txtResult.Multiline = true;
this.txtResult.Name = "txtResult";
this.txtResult.Size = new System.Drawing.Size(, );
this.txtResult.TabIndex = ;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "WMI:";
//
// txtWMI
//
this.txtWMI.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtWMI.Location = new System.Drawing.Point(, );
this.txtWMI.Name = "txtWMI";
this.txtWMI.Size = new System.Drawing.Size(, );
this.txtWMI.TabIndex = ;
this.txtWMI.Text = "select * from Win32_PhysicalMedia";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.txtWMI);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtResult);
this.Controls.Add(this.btnExecute);
this.Name = "Form1";
this.Text = "WMI Tester";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Button btnExecute;
private System.Windows.Forms.TextBox txtResult;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtWMI;
}
}

WMI tester的更多相关文章

  1. C#通过WMI的wind32 的API函数实现msinfo32的本地和远程计算机的系统日志查看功能

    先不说如何实现,先来看看效果图: 读取远程的需要提供下远程的计算用户名和密码即可. 如何实现这个代码功能,请看如下代码部分: 实体类: using System; using System.Colle ...

  2. 迁移Reporting Services的方法与WMI错误

    今天上午,接到一个任务:迁移SQL SERVER 2005的报表服务到另外一台SQL SERVER 2008服务器,结果等我备份了两边服务器的ReportServer,ReportServerTemp ...

  3. silverlight 4.0 的oob模式下,调用com通过wmi重启自身进程 killself

    silverlight目前开发的应用,想做到系统内注销后自动重新启动下 sllauncher.exe ,实现方式是通过WMI的COM接口,获取到当前应用的执行命令行(CommandLine):并通过s ...

  4. 通过WMI接口监控服务器性能

    WMI 是微软操作系统的一个内置的组件,通过使用WMI我们可以获取服务器硬件信息.收集服务器性能数据.操作Windows服务,甚至可以远程关机或是重启服务器. 一.在C#编程中使用WMI 要想在C#程 ...

  5. [问题记录.dotnet]取网卡信息报错"找不到"-WMI - Not found

    异常: System.Management.ManagementException: 找不到     在 System.Management.ManagementException.ThrowWith ...

  6. 使用WMI和性能计数器监控远程服务器权限设置

    应用场景:在web服务器中,通过.NET编码使用WMI查询远程服务器的一些硬件配置信息,使用性能计数器查询远程机器的运行时资源使用情况.在网上没有找到相关的东西,特记录与大家共享. 将web服务器和所 ...

  7. WMI 硬件类简单介绍,默认打印机

    获取默认打印机: SELECT * FROM Win32_Printer WHERE Default=True 常用的几个WMI: 主板:Win32_BaseBoard http://msdn.mic ...

  8. C#:基于WMI查询USB设备信息 及 Android设备厂商VID列表

    /* ---------------------------------------------------------- 文件名称:WMIUsbQuery.cs 作者:秦建辉 MSN:splashc ...

  9. windows不能显示此连接属性。windows management instrumentation (WMI) 信息可能损坏

    Windows Management Instrumentation (WMI)信息可能损坏错误修复 在 查看“本地连接”的属性,并切换到“高级”选项卡后,提示:“Windows不能显示此连接的属性. ...

随机推荐

  1. Unity Canvas vs Panel

    Unity guys specifically gave a performance talk about UI Canvases on some of the past Unite(s). You ...

  2. Mac上配置maven+eclipse+spark开发环境

    1.安装jdk 2.下载scala-ide.官网:http://scala-ide.org 3.安装maven 4.在eclipse中,配置maven的安装了路径.偏好设置--->maven-- ...

  3. html之跳转锚

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 学习HTML+JSP(更新中)

    1.HTML文档=网页 2.html是超文本标记语言的的缩写 超文本:超越普通文本,可以在文档中添加普通文本不能添加的元素,如:图片.视频.超链接等 标记语言:本身没有逻辑能力和执行能力,只被读取 脚 ...

  5. python 对 sqlite3的简单使用

    SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成.Python就内 ...

  6. ES6学习重难点总结(持续更新)

    Symbol 1.Symbol.iterator Symbol.iterator指向对象的默认遍历器方法: String.prototype[Symbol.iterator] //ƒ [Symbol. ...

  7. Beta冲刺第二周王者荣耀交流协会第六次会议

    1.立会照片 成员:王超,高远博,冉华,王磊,王玉玲,任思佳,袁玥全部到齐. master:任思佳 2.时间跨度: 2017年11月22日 12:00 — 12:20,总计20分钟. 3.地点: 一食 ...

  8. Django JWT Token RestfulAPI用户认证

    一般情况下我们Django默认的用户系统是满足不了我们的需求的,那么我们会对他做一定的扩展 创建用户项目 python manage.py startapp users 添加项目apps INSTAL ...

  9. 蓝桥每周一题之1. 3n+1 问题

    [问题描述] 考虑如下的序列生成算法:从整数 n 开始,如果 n 是偶数,把它除以 2:如果 n 是奇数,把它乘 3 加1.用新得到的值重复上述步骤,直到 n = 1 时停止.例如,n = 22 时该 ...

  10. 常见JS倒计时

    https://www.jb51.net/Special/356.htm  //JS倒计时  <button onclick="resetTime(60)">启动倒计时 ...