Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. vb6 to vb.net help needed

vb6 to vb.net help needed

Scheduled Pinned Locked Moved Visual Basic
csharpwinformsgraphicshelp
16 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O offroaderdan

    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?

    D Offline
    D Offline
    Dave Kreskowiak
    wrote on last edited by
    #7

    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...

    O 1 Reply Last reply
    0
    • D Dave Kreskowiak

      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...

      O Offline
      O Offline
      offroaderdan
      wrote on last edited by
      #8

      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

      O 1 Reply Last reply
      0
      • O offroaderdan

        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

        O Offline
        O Offline
        offroaderdan
        wrote on last edited by
        #9

        i have tried using the code you said but got this far, how do i fix it?

        Imports System
        Imports System.Management
        Public Class Form1

        Private 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!! :)

        L D J 3 Replies Last reply
        0
        • O offroaderdan

          i have tried using the code you said but got this far, how do i fix it?

          Imports System
          Imports System.Management
          Public Class Form1

          Private 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!! :)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #10

          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![^]

          1 Reply Last reply
          0
          • O offroaderdan

            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?

            T Offline
            T Offline
            Thomas Krojer
            wrote on last edited by
            #11

            definitly not ... imports ... not in vb6

            1 Reply Last reply
            0
            • O offroaderdan

              i have tried using the code you said but got this far, how do i fix it?

              Imports System
              Imports System.Management
              Public Class Form1

              Private 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!! :)

              D Offline
              D Offline
              DaveAuld
              wrote on last edited by
              #12

              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

              O 1 Reply Last reply
              0
              • D DaveAuld

                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

                O Offline
                O Offline
                offroaderdan
                wrote on last edited by
                #13

                :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!

                D 1 Reply Last reply
                0
                • O offroaderdan

                  :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!

                  D Offline
                  D Offline
                  DaveAuld
                  wrote on last edited by
                  #14

                  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!

                  Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                  O 1 Reply Last reply
                  0
                  • O offroaderdan

                    i have tried using the code you said but got this far, how do i fix it?

                    Imports System
                    Imports System.Management
                    Public Class Form1

                    Private 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!! :)

                    J Offline
                    J Offline
                    John M Bundy
                    wrote on last edited by
                    #15

                    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[^]

                    1 Reply Last reply
                    0
                    • D DaveAuld

                      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!

                      Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                      O Offline
                      O Offline
                      offroaderdan
                      wrote on last edited by
                      #16

                      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 If

                      Is there any way that with each drive a list box can be dedicated to that drive rather than having a massive list? Many thanks

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups