vb6 to vb.net help needed
-
no i thought it was orignally written in vb6 however it aint i copied and pasted the code into vb.net however when trying to run it this doesn't work?
See my reply to your other post. There's a link to an example of executing a WMI query in there.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
See my reply to your other post. There's a link to an example of executing a WMI query in there.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...Thanks for the reply, this has now rely confused me. What would do i simply do something along the lines off Dim instance As ManagementObjectSearcher Dim returnValue As ManagementObjectCollection returnValue = instance.Get() and then something like SELECT SerialNumber FROM Win32_BIOS" ?? i have never really tried anything like this before so its all new to me
-
Thanks for the reply, this has now rely confused me. What would do i simply do something along the lines off Dim instance As ManagementObjectSearcher Dim returnValue As ManagementObjectCollection returnValue = instance.Get() and then something like SELECT SerialNumber FROM Win32_BIOS" ?? i have never really tried anything like this before so its all new to me
i have tried using the code you said but got this far, how do i fix it?
Imports System
Imports System.Management
Public Class Form1Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Overloads Shared Function \_ Main(ByVal args() As String) As Integer End Function 'Main Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s As New ManagementObjectSearcher( \_ select SerialNumber from Win32\_BIOS"" ' the bit of code you told me to put in it!! New EnumerationOptions( \_ Nothing, System.TimeSpan.MaxValue, 1, \_ True, False, True, True, False, \_ True, True)) For Each service As ManagementObject In s.Get() 'show the instance TextBox1.Text = (service.ToString()) Next End Sub
End Class
thanks Dave for the help!! :)
-
i have tried using the code you said but got this far, how do i fix it?
Imports System
Imports System.Management
Public Class Form1Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Overloads Shared Function \_ Main(ByVal args() As String) As Integer End Function 'Main Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s As New ManagementObjectSearcher( \_ select SerialNumber from Win32\_BIOS"" ' the bit of code you told me to put in it!! New EnumerationOptions( \_ Nothing, System.TimeSpan.MaxValue, 1, \_ True, False, True, True, False, \_ True, True)) For Each service As ManagementObject In s.Get() 'show the instance TextBox1.Text = (service.ToString()) Next End Sub
End Class
thanks Dave for the help!! :)
something like this
Public Sub q() Dim s As New ManagementObjectSearcher( \_ "root\\MyApp", \_ "SELECT SerialNumber FROM Win32\_BIOS", \_ New EnumerationOptions( \_ Nothing, System.TimeSpan.MaxValue, 1, \_ True, False, True, True, False, \_ True, True)) For Each service As ManagementObject In s.Get() 'show the instance TextBox1.Text = (service.ToString()) Next End Sub
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
-
no i thought it was orignally written in vb6 however it aint i copied and pasted the code into vb.net however when trying to run it this doesn't work?
definitly not ... imports ... not in vb6
-
i have tried using the code you said but got this far, how do i fix it?
Imports System
Imports System.Management
Public Class Form1Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Overloads Shared Function \_ Main(ByVal args() As String) As Integer End Function 'Main Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s As New ManagementObjectSearcher( \_ select SerialNumber from Win32\_BIOS"" ' the bit of code you told me to put in it!! New EnumerationOptions( \_ Nothing, System.TimeSpan.MaxValue, 1, \_ True, False, True, True, False, \_ True, True)) For Each service As ManagementObject In s.Get() 'show the instance TextBox1.Text = (service.ToString()) Next End Sub
End Class
thanks Dave for the help!! :)
Here, Create a new winforms project; Add a reference to System.Management Add 2 List boxes to your form and a button with name to match the code below and Run it.
Imports System.Management
Public Class Form1
Private Sub Form1\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Enumarate Drives List For Each drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives ListBox1.Items.Add(drive.Name) Next End Sub Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ListBox1.SelectedItems.Count > 0 Then ListBox2.Items.Clear() 'Get the WMI Properties for the Drive and populate the list box Dim query As New SelectQuery("Win32\_LogicalDisk") 'ManagementObjectSearcher retrieves a collection of WMI objects based on the query. Dim search As New ManagementObjectSearcher(query) ' Display each entry for Win32\_LogicalDisk Dim info As ManagementObject For Each info In search.Get() For Each item As PropertyData In info.Properties ListBox2.Items.Add(item.Name & " : " & item.Value) Next Next End If End Sub
End Class
Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo
modified on Wednesday, October 28, 2009 1:10 PM
-
Here, Create a new winforms project; Add a reference to System.Management Add 2 List boxes to your form and a button with name to match the code below and Run it.
Imports System.Management
Public Class Form1
Private Sub Form1\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Enumarate Drives List For Each drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives ListBox1.Items.Add(drive.Name) Next End Sub Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ListBox1.SelectedItems.Count > 0 Then ListBox2.Items.Clear() 'Get the WMI Properties for the Drive and populate the list box Dim query As New SelectQuery("Win32\_LogicalDisk") 'ManagementObjectSearcher retrieves a collection of WMI objects based on the query. Dim search As New ManagementObjectSearcher(query) ' Display each entry for Win32\_LogicalDisk Dim info As ManagementObject For Each info In search.Get() For Each item As PropertyData In info.Properties ListBox2.Items.Add(item.Name & " : " & item.Value) Next Next End If End Sub
End Class
Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo
modified on Wednesday, October 28, 2009 1:10 PM
:laugh: :laugh: :laugh: :D works like a treat! However is there any way that i can get drive "C" to appear and in a textbox and have volume serial number of the drive in a txtbox. so it would look something like this text box 1 contents = volume serial "blah blah blah"( number) of "C" I have never really played around with list boxes, i only really know txt boxes and labels!! Many thanks Dave!
-
:laugh: :laugh: :laugh: :D works like a treat! However is there any way that i can get drive "C" to appear and in a textbox and have volume serial number of the drive in a txtbox. so it would look something like this text box 1 contents = volume serial "blah blah blah"( number) of "C" I have never really played around with list boxes, i only really know txt boxes and labels!! Many thanks Dave!
Thats just basic string manipulation. If you can't work that out you shouldn't be trying to mess about with WMI! Also if you look at the documentation for the classes used, you will see it is also possible to query just the single property you want, rather than have to iterate each one. Go try and figure it out, and then come back with what you tried if you have problems. I am not going to do it all for you!
-
i have tried using the code you said but got this far, how do i fix it?
Imports System
Imports System.Management
Public Class Form1Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Overloads Shared Function \_ Main(ByVal args() As String) As Integer End Function 'Main Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s As New ManagementObjectSearcher( \_ select SerialNumber from Win32\_BIOS"" ' the bit of code you told me to put in it!! New EnumerationOptions( \_ Nothing, System.TimeSpan.MaxValue, 1, \_ True, False, True, True, False, \_ True, True)) For Each service As ManagementObject In s.Get() 'show the instance TextBox1.Text = (service.ToString()) Next End Sub
End Class
thanks Dave for the help!! :)
I'm not sure where you're headed with what you have, but try here, I downloaded the sample and it worked great. It is in Csharp but that is easy to convert if you need to http://www.eggheadcafe.com/articles/20021019.asp[^]
-
Thats just basic string manipulation. If you can't work that out you shouldn't be trying to mess about with WMI! Also if you look at the documentation for the classes used, you will see it is also possible to query just the single property you want, rather than have to iterate each one. Go try and figure it out, and then come back with what you tried if you have problems. I am not going to do it all for you!
ok i had ago with the changing the code around this is how far i got t cant seem to figure it out all i need is if drive "c" contains a volume serial number then that is placed on a text box i had a go at changing For Each drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives ListBox1.Items.Add(drive.Name) Next to Dim drive as system.io.driveInfo listbox1.items.add("C:/") this seemed to work however in list box 2 it still displayed 4 drives?? i tried to extract certain bits of data from lit box to textbox, however this didn't work.
If ListBox2.Items.Contains("VolumeSerialNumber" & " : " & item.value) Then
TextBox1.Text = "VolumeSerialNumber" & " : " & item.value
End IfIs there any way that with each drive a list box can be dedicated to that drive rather than having a massive list? Many thanks