469,579 Members | 1,157 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Computer Information in VB.NET

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
Jul 19 '05 #1
4 27119
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" <Ji*****@charter.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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

Jul 19 '05 #2
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 theselect 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" <Ji*****@charter.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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

.

Jul 19 '05 #3
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

"Jim Scheffler" <Ji*****@charter.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #4
You want to set the Scope property on the ManagementObjectSearcher.
http://msdn.microsoft.com/library/en...ScopeTopic.asp

http://msdn.microsoft.com/library/en...ClassTopic.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\\ro ot\\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
"Jim Scheffler" <Ji*****@charter.com> wrote in message
news:el**************@tk2msftngp13.phx.gbl...
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

"Jim Scheffler" <Ji*****@charter.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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


Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Lamont | last post: by
reply views Thread by Mahesh Kumar | last post: by
5 posts views Thread by z. f. | last post: by
6 posts views Thread by Jim Scheffler | last post: by
7 posts views Thread by =?Utf-8?B?TWljaGFlbCBkZSBWZXJh?= | last post: by
reply views Thread by Winder | last post: by
reply views Thread by =?Utf-8?B?R3JlZw==?= | last post: by
2 posts views Thread by =?Utf-8?B?R3JlZw==?= | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.