Click here to Skip to main content
15,562,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Following is my code to get UUID of my PC. I'm finding Error. Pls help me to resolve the errors. I'm getting Error on "ManagementObjectSearcher" is not defind & "ManagementObject" is not defind.

What I have tried:

Option Strict On

Imports System
Imports System.Management
Imports System.Windows.Forms

Imports Microsoft.VisualBasic

Imports System.Diagnostics 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim readValue As String
            Dim searcher As New ManagementObjectSearcher("root\CIMV2",
                    "SELECT * FROM Win32_ComputerSystemProduct")

            For Each queryObj As ManagementObject In searcher.Get()

                Console.WriteLine("Win32_ComputerSystemProduct instance")
                readValue = "UUID: " & queryObj("UUID")
                RichTextBox1.Text = RichTextBox1.Text & Chr(13) & Chr(10) & readValue
        Catch err As Exception
            MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
        End Try
    End Sub
Updated 15-May-22 0:32am
Richard MacCutchan 15-May-22 3:08am    
What errors? Please do not expect us to guess what you see on your screen.

1 solution

At a guess - and that's all it can be given the absence of information - you haven't added a reference to the System.Management.dll: ManagementObjectSearcher Class (System.Management) | Microsoft Docs[^]
Share this answer
Member 13839801 15-May-22 6:01am    
I'm getting error : "ManagementObjectSearcher" is not defind.
Also : "ManagementObject" is not defind.

Pls help me.
OriginalGriff 15-May-22 6:06am    
Have you checked your references?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900