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不能显示此连接的属性. ...
随机推荐
- grid-layout
<!-- 创建三个网格布局--> .wrapper { <!--创建一个网格布局 --> display: grid; <!--创建3列 且每列都等距 --> gr ...
- 可编程逻辑控制器(PLC)漏洞挖掘思路与验证
mailto wangkai0351@gmail.com 随时记录千奇百怪的漏洞挖掘思路,主要针对STEP7 v5+西门子S7-300/400系列PLC,欢迎同行前来交流. 组态信息下载完整性攻击 思 ...
- linux的ls命令中文件颜色含义
linux命令ls会显示出文件的颜色, 系统约定的默认颜色含义如下: 白色:表示普通文件 蓝色:表示目录 绿色:表示可执行文件 红色:表示压缩文件 浅蓝色:链接文件 主要是使用ln命令建立的文件 红色 ...
- 根据图片URL获取图片的尺寸【Swift语言实现】
import UIKit extension UIImage { /// 获取网络图片尺寸 /// /// - Parameter url: 网络图片链接 /// - Returns: 图片尺寸siz ...
- TCP端口检测工具
很多时候,我们需要测试 tcp 端口.ping 命令虽然好用,但不能测试端口,因为 ping 基于ICMP协议,属于IP层协议,所以无法测试传输层的 TCP/UDP 端口.幸好有tcping命令,可以 ...
- 第三次scrum冲刺
第三次冲刺 一.第三次冲刺任务 ! 在已有的基础上实现图书馆管理员对图书信息的查询以及对图书借阅情况的查询. 二.用户故事 本次的用户是图书馆的管理员 用户输入对应的管理员的账号和密码 用户选择图书 ...
- Linux~Archer 进化之路
使用过的linux系统有:Redhat.红旗Linux.Deepin.Ubuntu.Debian.Fedora.Kali.Parrot.manjaro.Mint.Arch,最早接触linux是从200 ...
- 怎么在Mac上安装Tomcat 7[转载]
本文来自http://wolfpaulus.com/journal/mac/tomcat7,谢谢Wolf Paulus 的分享 Tomcat 7 是Apache发布的第一款可以支持Servlet 3. ...
- jasperreports+IReport 5.56,集成到Spring MVC4.0案例
首先,先说一下需求,项目需要打印一些报表,也没多想,直接就在jsp页面设置了样式,前台直接调用window.print()写了打印功能,但是例会的时候,领导提出需要一些比较麻烦的打印,自己写肯定费时间 ...
- Consider defining a bean of type 'com.lvjing.dao.DeviceStatusMapper' in your configuration.
"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-javaagent:C:\Program Files\JetBra ...