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不能显示此连接的属性. ...
随机推荐
- java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp
java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp 错误是因为时间类型出现了0 ...
- selenium的三种等待方式
selenium有三种等待方式 1.time.sleep() 设置等待最简单的方法就是强制等待,但一般不建议使用,可以在调试的时候进行使用 2.隐性等待 driver.implictily_wait( ...
- 日积月累---JVM01
Java体系结构包括四个独立但相关的技术: Java程序设计语言 Java class文件格式 Java应用编程接口 Java虚拟机 用Java编程语言编写源代码,把它编译成Java class文件, ...
- 使goroutine同步的方法总结
前言: 在前面并发性能对比的文章中,我们可以看到Golang处理大并发的能力十分强劲,而且开发也特别方便,只需要用go关键字即可开启一个新的协程. 但当多个goroutine同时进行处理的时候,就会遇 ...
- git和github的第一次接触
我的github的helloworld链接: https://github.com/xuziqian111/hello-world/blob/master/helloworld.java 我的gith ...
- Real time profiler for Delphi applications
xalion提供的资源,这么强,还是免费的,快去试用! ✓ Detailed debug information (internal, TDS, MAP) ✓ Display informat ...
- 基于testng框架的web自动化测试
package baidutest; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.o ...
- ln语法
Linux文件系统中,有所谓的链接(link),我们可以将其视为档案的别名,而链接又可分为两种 : 硬链接(hard link)与软链接(symbolic link),硬链接的意思是一个文件可以有多个 ...
- Spring事务管理transactionManager
bean.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...
- outlook2010设置失败后重新设置
1.WIN+R ,然后在弹出框中输入outlook /importprf .\.prf 2.重新设置.