Computer Information in VB.NET

  • Thread starter Thread starter Jim Scheffler
  • Start date Start date
J

Jim Scheffler

I'm new to VB.NET programming and would like some help on a little project
I've got going.
How would I go about getting computer information on my local computer, i.e.
serial number, hard drive size, memory installed, etc. Then take it one step
further and gather this info for all computers on a network.

I really appreciate any help on this,

Jim Scheffler
 
WMI is your friend. Look at the ManagementObject classes and examples. This a C#
example for logical disks, but all you need to change is the target of the
select sttement and the properties you ask for. Doing it to remote computers is
"free". Just use a period for local system or the server name for remote.

public void LDisk ()
{
StringBuilder st = new StringBuilder ();
string servername = "somesystem";
ObjectQuery oq = new ObjectQuery("select * from Win32_Logicaldisk");
ManagementScope scope = new ManagementScope("\\\\" + servername +
"\\root\\cimv2");
scope.Connect();
ManagementObjectSearcher sea = new ManagementObjectSearcher(scope, oq);
foreach (ManagementObject proc in sea.Get())
{
st.AppendFormat ("Desc = {0}, ID={1}, Volname={2}", proc["Description"],
proc["Deviceid"],proc["VolumeName"]);
st.AppendFormat("\n");
}
MessageBox.Show (st.ToString());
}
 
Thanks Phil, That does look like exactly what I'm looking
for. I will check into it.

Jim
-----Original Message-----
WMI is your friend. Look at the ManagementObject classes and examples. This a C#
example for logical disks, but all you need to change is the target of the
select sttement and the properties you ask for. Doing it to remote computers is
"free". Just use a period for local system or the server name for remote.

public void LDisk ()
{
StringBuilder st = new StringBuilder ();
string servername = "somesystem";
ObjectQuery oq = new ObjectQuery("select * from Win32_Logicaldisk");
ManagementScope scope = new ManagementScope("\\\\" + servername +
"\\root\\cimv2");
scope.Connect();
ManagementObjectSearcher sea = new
ManagementObjectSearcher(scope, oq);
foreach (ManagementObject proc in sea.Get())
{
st.AppendFormat ("Desc = {0}, ID={1}, Volname={2}", proc["Description"],
proc["Deviceid"],proc["VolumeName"]);
st.AppendFormat("\n");
}
MessageBox.Show (st.ToString());
}

--
Phil Wilson [MVP Windows Installer]
----
Jim Scheffler said:
I'm new to VB.NET programming and would like some help on a little project
I've got going.
How would I go about getting computer information on my local computer, i.e.
serial number, hard drive size, memory installed, etc. Then take it one step
further and gather this info for all computers on a network.

I really appreciate any help on this,

Jim Scheffler


.
 
Hello,

Here is an update on this project I'm working on,

So far I've been able to get information from my local computer using the
code below,

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim search As New ManagementObjectSearcher("SELECT * FROM Win32_BIOS")

Dim search2 As New ManagementObjectSearcher("SELECT * FROM
Win32_ComputerSystem")

Dim search3 As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")

Dim info As ManagementObject

For Each info In search.Get()

TextBox1.Text = "Serial Number: " & info("serialnumber").ToString() & CRLF

TextBox1.Text += "Manufacturer: " & info("Manufacturer").ToString() & CRLF

Next

For Each info In search2.Get()

TextBox1.Text() += "Model: " & info("Model").ToString() & CRLF

TextBox1.Text() += "Computer Name: " & info("Name").ToString() & CRLF

TextBox1.Text() += "User Name Logged in: " & info("UserName").ToString() &
CRLF & CRLF

TextBox1.Text() += "Total Physical Memory: " &
info("TotalPhysicalMemory").ToString() & (" KB of Ram") & CRLF

Next

For Each info In search3.Get()

TextBox1.Text() += "CPU Clock Speed: " & info("Name").ToString() & CRLF

Next

End Sub

Some of this code was cut and pasted from other snips of code I found on the
internet and some of it I wrote myself, I'm still new at this.

Anyhow, now I want to get this info from computers on my network. From what
I read WMI is using the default namespace or local computer to get this
info. How would I code in a different computer to get this info? I can't
seem to find any good examples of this on the web.



Thanks,

Jim
 
You want to set the Scope property on the ManagementObjectSearcher.
http://msdn.microsoft.com/library/e...ntManagementObjectSearcherClassScopeTopic.asp

http://msdn.microsoft.com/library/e...SystemManagementManagementScopeClassTopic.asp

In C# it looks something like this:
System.Management.ConnectionOptions options = new
System.Management.ConnectionOptions();
options.Username = "username"; //could be in domain\user format
options.Password = "Secret!!!";
// specify the path to the remote machine (un-double the slashes for VB)
System.Management.ManagementScope scope = new
System.Management.ManagementScope("\\\\machine\\root\\cimv2", options);

// Get the list of configured printers:
string strQuery= "SELECT * FROM Win32_Printer";
System.Management.ObjectQuery oq = new
System.Management.ObjectQuery(strQuery);
System.Management.ManagementObjectSearcher query1 = new
System.Management.ManagementObjectSearcher(scope, oq);
System.Management.ManagementObjectCollection queryCollection1 =
query1.Get();



-Dino
Microsoft
 
Back
Top