Click here to Skip to main content
15,907,687 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Add rows from one datagridview to another Pin
dptalt20-Apr-07 2:39
dptalt20-Apr-07 2:39 
GeneralRe: Add rows from one datagridview to another Pin
Hansduncan20-Apr-07 20:47
Hansduncan20-Apr-07 20:47 
GeneralRe: Add rows from one datagridview to another Pin
dptalt23-Apr-07 2:32
dptalt23-Apr-07 2:32 
GeneralRe: Add rows from one datagridview to another Pin
Hansduncan23-Apr-07 2:51
Hansduncan23-Apr-07 2:51 
QuestionCancel Event Pin
dptalt19-Apr-07 10:30
dptalt19-Apr-07 10:30 
AnswerRe: Cancel Event Pin
nlarson117-May-07 7:41
nlarson117-May-07 7:41 
QuestionSerialNumber of an Xp Machine Pin
Thoombath19-Apr-07 10:26
Thoombath19-Apr-07 10:26 
AnswerRe: SerialNumber of an Xp Machine Pin
Dave Kreskowiak19-Apr-07 15:32
mveDave Kreskowiak19-Apr-07 15:32 
You've missed an important detail. You need to specify a scope, or which WMI namespace you want to search and which machine to search. In the example below, that period in the scope string specifies the local machine:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ' Important!!  MUST use \root\cimv2 here!  \root\default does NOT work!
    Dim scope As New ManagementScope("\\.\root\cimv2")

    ' Clear out the ListView we're using to show the drives and serial numbers.
    ListView1.Items.Clear()

    Dim query As New ObjectQuery("SELECT * FROM Win32_PhysicalMedia")
    Dim searcher As New ManagementObjectSearcher(scope, query)
    Dim objectCollection As ManagementObjectCollection = searcher.Get()
    For Each obj As ManagementObject In objectCollection
        ' The ListView is assumed to have two columns setup to old these.
        Dim newItem As New ListViewItem(New String() {CStr(obj("Tag")), CStr(obj("SerialNumber")).Trim})
        ListView1.Items.Add(newItem)
    Next

    ' It's very important to dispose these objects when your done with them!  If
    ' you don't, you'll end up with a handle leak and eventually crash the system.
    objectCollection.Dispose()
    searcher.Dispose()
End Sub

Now, like I said before, not every device fills in the information you want. In one of my test systems, only 2 out of 6 hard drives returned serial numbers, and one of those needed to be Trim'd to remove some leading spaces.


Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007


GeneralRe: SerialNumber of an Xp Machine Pin
Thoombath20-Apr-07 4:47
Thoombath20-Apr-07 4:47 
GeneralRe: SerialNumber of an Xp Machine Pin
Dave Kreskowiak20-Apr-07 4:52
mveDave Kreskowiak20-Apr-07 4:52 
GeneralRe: SerialNumber of an Xp Machine Pin
Thoombath20-Apr-07 5:41
Thoombath20-Apr-07 5:41 
GeneralRe: SerialNumber of an Xp Machine Pin
Dave Kreskowiak20-Apr-07 6:06
mveDave Kreskowiak20-Apr-07 6:06 
GeneralRe: SerialNumber of an Xp Machine Pin
Thoombath20-Apr-07 6:51
Thoombath20-Apr-07 6:51 
GeneralRe: SerialNumber of an Xp Machine Pin
Dave Kreskowiak20-Apr-07 7:10
mveDave Kreskowiak20-Apr-07 7:10 
GeneralRe: SerialNumber of an Xp Machine Pin
Thoombath20-Apr-07 8:15
Thoombath20-Apr-07 8:15 
GeneralRe: SerialNumber of an Xp Machine Pin
Dave Kreskowiak20-Apr-07 8:40
mveDave Kreskowiak20-Apr-07 8:40 
GeneralRe: SerialNumber of an Xp Machine Pin
Thoombath20-Apr-07 11:00
Thoombath20-Apr-07 11:00 
QuestionSerialNumber/HardDrive Details Pin
Thoombath19-Apr-07 9:41
Thoombath19-Apr-07 9:41 
AnswerRe: SerialNumber/HardDrive Details Pin
Dave Kreskowiak19-Apr-07 9:45
mveDave Kreskowiak19-Apr-07 9:45 
GeneralRe: SerialNumber/HardDrive Details Pin
Thoombath19-Apr-07 10:29
Thoombath19-Apr-07 10:29 
QuestionStartup Project Pin
TenmanS1419-Apr-07 6:50
TenmanS1419-Apr-07 6:50 
AnswerRe: Startup Project Pin
Dave Kreskowiak19-Apr-07 7:10
mveDave Kreskowiak19-Apr-07 7:10 
GeneralRe: Startup Project Pin
TenmanS1419-Apr-07 7:11
TenmanS1419-Apr-07 7:11 
GeneralRe: Startup Project Pin
kubben19-Apr-07 8:57
kubben19-Apr-07 8:57 
GeneralRe: Startup Project Pin
Dave Kreskowiak19-Apr-07 9:03
mveDave Kreskowiak19-Apr-07 9:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.