CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2010
    Posts
    4

    How to read a Registry value??

    I got this code.

    I want to read a string from a registry key, if its 0 do one thing, and if its 1, do something else.

    This code (if it works..) would at the first time create a sub key, and assign it to 1, but if its not existing, it would then show a few messageboxe's - But it doesnt work, even if I set it to 1 or 0, it won't work, it always displays the messages.

    If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\A Sim Game Studios\A Sim Game - Business",
    "FirstRun", "1") Then


    MessageBox.Show("Your name is Jay J, you are 23 years old")
    MessageBox.Show("You are a grad student that can't find a job in a tough world")
    MessageBox.Show("You decide to make something of yourself - beginning with the 50$ in your pockets you set out to become one of the biggest business owners in your city")
    End If

    My.Computer.Registry.SetValue("HKEY_CURRENT_USER\A Sim Game Studios\A Sim Game - Business",
    "FirstRun", "1")

    Anyone can help?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to read a Registry value??

    What OS? Probably needs ADMIN permission to access the registry.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How to read a Registry value??

    mistake is: last parameter of getValue "1" is for the default value. That is: if it does not find the key, it returns 1.
    Set it to 0, instead, to get false in your if...By the way: as dglienna told you, you will need permission to access registry. Thus, you might get always the default value in any case...
    ie:
    Code:
    If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\A Sim Game Studios\A Sim Game - Business", "FirstRun", "0") Then
       MessageBox.Show("Your name is Jay J, you are 23 years old")
       MessageBox.Show("You are a grad student that can't find a job in a tough world")
       MessageBox.Show("You decide to make something of yourself - beginning with the 50$ in your pockets you set out to become one of the biggest business owners in your city")
    End If
    
    My.Computer.Registry.SetValue("HKEY_CURRENT_USER\A Sim Game Studios\A Sim Game - Business","FirstRun", "1")
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured