WMI tester
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的更多相关文章
- C#通过WMI的wind32 的API函数实现msinfo32的本地和远程计算机的系统日志查看功能
先不说如何实现,先来看看效果图: 读取远程的需要提供下远程的计算用户名和密码即可. 如何实现这个代码功能,请看如下代码部分: 实体类: using System; using System.Colle ...
- 迁移Reporting Services的方法与WMI错误
今天上午,接到一个任务:迁移SQL SERVER 2005的报表服务到另外一台SQL SERVER 2008服务器,结果等我备份了两边服务器的ReportServer,ReportServerTemp ...
- silverlight 4.0 的oob模式下,调用com通过wmi重启自身进程 killself
silverlight目前开发的应用,想做到系统内注销后自动重新启动下 sllauncher.exe ,实现方式是通过WMI的COM接口,获取到当前应用的执行命令行(CommandLine):并通过s ...
- 通过WMI接口监控服务器性能
WMI 是微软操作系统的一个内置的组件,通过使用WMI我们可以获取服务器硬件信息.收集服务器性能数据.操作Windows服务,甚至可以远程关机或是重启服务器. 一.在C#编程中使用WMI 要想在C#程 ...
- [问题记录.dotnet]取网卡信息报错"找不到"-WMI - Not found
异常: System.Management.ManagementException: 找不到 在 System.Management.ManagementException.ThrowWith ...
- 使用WMI和性能计数器监控远程服务器权限设置
应用场景:在web服务器中,通过.NET编码使用WMI查询远程服务器的一些硬件配置信息,使用性能计数器查询远程机器的运行时资源使用情况.在网上没有找到相关的东西,特记录与大家共享. 将web服务器和所 ...
- WMI 硬件类简单介绍,默认打印机
获取默认打印机: SELECT * FROM Win32_Printer WHERE Default=True 常用的几个WMI: 主板:Win32_BaseBoard http://msdn.mic ...
- C#:基于WMI查询USB设备信息 及 Android设备厂商VID列表
/* ---------------------------------------------------------- 文件名称:WMIUsbQuery.cs 作者:秦建辉 MSN:splashc ...
- windows不能显示此连接属性。windows management instrumentation (WMI) 信息可能损坏
Windows Management Instrumentation (WMI)信息可能损坏错误修复 在 查看“本地连接”的属性,并切换到“高级”选项卡后,提示:“Windows不能显示此连接的属性. ...
随机推荐
- Python处理数据库
使用数据库驱动连接数据库 (Connection对象) 打开游标(Cursor对象),并通过它执行SQL语句(execute方法) 提交操作(commit()) 关闭连接(close()) ORM将表 ...
- DevExpress v18.2新版亮点——DevExtreme篇(四)
行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍新版本新功能.本文将介绍了DevExtreme Complete Sub ...
- P3957 跳房子
题目描述 跳房子,也叫跳飞机,是一种世界性的儿童游戏,也是中国民间传统的体育游戏之一. 跳房子的游戏规则如下: 在地面上确定一个起点,然后在起点右侧画 n 个格子,这些格子都在同一条直线上.每个格子内 ...
- vs-code 基础设置
汉化设置: 最新版的vscode 汉化需要两步 1 ctrl+shift+p 在顶部输入框中输入 language 后选择 configure Display Language 后进入 第二张 ...
- 关于MySQL5.7 这几天的总结(json类型)
一开始,老板让调整一下 innodb_buffer_pool_size 大小,因为这台机器内存大. 看了下内存,16G,再SQL下面命令,得到结果是4G. SELECT @@innodb_buffer ...
- 马凯军201771010116《面向对象与程序设计Java》第十五周学习知识总结
实验十五 GUI编程练习与应用程序部署 一.知识学习部分 清单文件 每个JAR文件中包含一个用于描述归档特征的清单文件(manifest).清单文件被命名为MANIFEST.MF,它位于JAR文件的 ...
- 石头的Xcode学习列表
http://www.cnblogs.com/JangoJing/tag/xcode/
- python中的 uuid 模块使用示例
此模块提供不可变的 UUID 对象 (类 uuid) 和函数uuid1().uuid3().uuid4().uuid5(), 用于生成在 RFC 4122 中指定版本1.3.4和5UUIDs .如果你 ...
- 字符串与NUll的拼接问题
今天做项目,浏览器向后台传值的时候,碰到一个问题,声明变量的时候为null时,首次加载会报错.但是初始化一次后,就正常传值了,摸索了半天,终于找到问题所在.在此记录一下,谨记. 现在说说情况,我在JS ...
- 关于null的判断
Java中[null]的判断: 1.[null]只能通过is null,is not null判断,任何与的 关系运算(比较,有大于.大于等于.小于.小于等于.等于.不等于六种运算)都是false. ...