Skip to content

Instantly share code, notes, and snippets.

@andySF
Created May 25, 2012 06:11
Show Gist options
  • Save andySF/2786094 to your computer and use it in GitHub Desktop.
Save andySF/2786094 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.Reflection;
using IONClient.Collector;
using System.Net;
namespace IONClient
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
Machine machine = new Machine();
listBox3.Items.Add(machine.MachineName);
listBox3.Items.Add(machine.UserName);
listBox3.Items.Add(machine.OSName);
listBox3.Items.Add(machine.ServicePack);
listBox3.Items.Add(machine.InstallDate.ToString("dd/MM/yyyy-HH:mm:ss"));
listBox3.Items.Add(machine.BIOS);
foreach (var ip in machine.LocalIPAddress)
{
listBox3.Items.Add(ip);
}
}
ManagementObjectSearcher searcher;
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
try
{
String query = "select * from " + comboBox1.Text;
//String query = "select * from Win32_OperatingSystem";
searcher = new ManagementObjectSearcher(query);
listBox1.Items.Add(query);
foreach (ManagementObject share in searcher.Get())
{
listBox1.Items.Add(share.ToString());
}
}
catch
{
listBox1.Items.Add("error");
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox2.Items.Clear();
try
{
ManagementObject value = new ManagementObject(listBox1.SelectedItem.ToString());
foreach (PropertyData PC in value.Properties )
{
if (PC.Value != null && PC.Value.ToString() != "")
{
switch (PC.Value.GetType().ToString())
{
case "System.String[]":
string[] str = (string[])PC.Value;
string str2 = "";
foreach (string st in str)
str2 += st + " ";
listBox2.Items.Add(PC.Name+"="+str2);
break;
case "System.UInt16[]":
ushort[] shortData = (ushort[])PC.Value;
string tstr2 = "";
foreach (ushort st in shortData)
tstr2 += st.ToString() + " ";
listBox2.Items.Add(PC.Name + "=" + tstr2);
break;
default:
listBox2.Items.Add(PC.Name + "=" + PC.Value.ToString());
break;
}
}
else
{
//listBox2.Items.Add("No Information available");
continue;
}
}
}
catch { }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment