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的基础数据类型
Java 里面的数据类型从大的方面分为两类,一是基本数据类型,一是引用类型.基本的JAVA 数据类型层次图如下: Java 中的基本数据类型可分为四种:(1)逻辑型:boolean(2)文本型:cha ...
- Java将ip字符串转换成整数的代码
下面代码是关于Java将ip字符串转换成整数的代码,希望对各位有较大用途. public class IpUtil { public static int Ip2Int(String strIp){ ...
- java proxy 转包
package org.rx.socks.proxy; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; ...
- hadoop.create.0.1
#!/bin/shexit 0 linux单机分布式实验环境数据策略#数据:不同源 -v ,link 各自独立的文件夹#配置:同源,写时复制 存于docker images#程序体,基本不改变.或 ...
- DAY2:数据类型Python3.6
数字 1.int(整型) 2. long(长整型) 3.float(浮点型) 4.complex(复数) 布尔值 1.真或假 1或0表示 字符串 知识补充 字符串转二进制 mes = "北 ...
- [Chrome] 谷歌浏览器开启开发模式仍然无法安装油猴脚本
右键 > 属性 > 起始位置 > 添加 --enable-easy-off-store-extension-install 谷歌浏览器无法安装油猴脚本:--enable-easy-o ...
- Groovy学习笔记-动态类型
1.respondsTo方法判断对象是否存在指定方法 interface IHelp{ void helpMoveThings() } class Man implements IHelp{ void ...
- 泊爷带你学go -- redis连接池的操作
package main import ( "common" "fmt" "proto" "strconv" " ...
- 第三次Scrum编程冲刺
小组第三次冲刺的任务及其完成情况描述 回顾第二次任务,完成了基本业务:用户可以使拍摄视频并上传至个人的空间页面,来与关注他的粉丝分享.关注“长大故事”社区中的其他用户,来了解别人的动态.别人所发动态下 ...
- parallel::ForkManager
use Parallel::ForkManager; my $MAX_PROCESSES=10; #申明最大进程数(一次创建的进程越多,越耗内存): my $pm = new Parallel:: ...