[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Error with getting CPU information

Hello i am making a sidebar and i ofund source for it but when i coppy any past the code which is below
Dim Key As RegistryKey  = Registry.LocalMachine
            
      'read the value of the Key
            Key = Key.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0")
            val = Key.GetValue("~MHz")
            txtProc.Text = val & " (~MHz)"
            Key.Close
            key = nothing
It tells me Registry key is not defined when i look at my expample source it isnt defined anywhere any suggestions
0
Sony-Controlled
Asked:
Sony-Controlled
  • 5
  • 2
  • 2
1 Solution
 
PaulHewsCommented:
Add this to the first line of your module:
Imports Microsoft.Win32

or change your code like this:

        Dim Key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
        Dim Val As String

        'read the value of the Key
        Key = Key.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0")
        Val = CStr(Key.GetValue("~MHz"))
        MsgBox(Val & " (~MHz)")
        Key.Close()
        Key = Nothing
0
 
PaulHewsCommented:
It says it is not defined, because it is defined within the Microsoft.Win32 namespace.  Once you import that namespace, or reference the definition directly, it will be resolved.
0
 
Sony-ControlledAuthor Commented:
K it worked i had to change it from messagebox to a label but thanks for the helo
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
amyhxuCommented:
       Dim Key As Microsoft.Win32.RegistryKey
        Key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Hardware\Description\system\CentralProcessor\0")

        Dim keyVal As Integer
        Dim DefaultValue As Integer = 100  ' Set default value for the key according to the value type you define for the key
        If (Not Key Is Nothing) Then
            keyVal = Key.GetValue("~MHz", DefaultValue)
            Key.Close()
        Else
            ' some code in case the registry key does not exist
        End If

        txtProc.Text = keyVal & " (~MHz)"

0
 
amyhxuCommented:
Oops, I am late. But when I typed in the code, there was no comments yet :P
0
 
PaulHewsCommented:
If you found my solution helpful and complete, please grade with an A grade.  If you need more help, ask for it.  Thank you.
0
 
PaulHewsCommented:
You may not be aware, but if the solution is complete, it should be graded A as per the site guidelines:
http://www.experts-exchange.com/help.jsp#hi73

You may also not know that the points received by the expert are affected by the grade that you give.  
http://www.experts-exchange.com/help.jsp#hi20

If the solution was not complete I would have been happy to provide you with more information...

0
 
Sony-ControlledAuthor Commented:
I know and i grade how i wish and i did not belive it was complete i had to edit it to my standards therefore it is not complete ^ as you have seen in the above posted code it was as a text box you changed it to a mesage box i wanted it as a text box or a label there fore the code is not complete
0
 
PaulHewsCommented:
As you already had that part of the solution, and as that change I made was for my benefit only, I think we will have to agree to disagree.  Also, adding the imports statement would not require you to change your code at all.  But thanks for the points anyway.  Good luck with your project.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now