Results 1 to 4 of 4

Thread: [RESOLVED] How can i use this code to add registry entry?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Uk
    Posts
    157

    Resolved [RESOLVED] How can i use this code to add registry entry?

    I want to create a registry entry when the user presses Alt F6 F6

    Could someone give me an example of house to do this?

    I'm playing with this code

    Code:
              'Adds registry entry when Alt + F6 + F6 is pressed
                If e.Alt And e.KeyCode.ToString = "F6" And e.KeyCode.ToString = "F6" Then
                    Dim regKey As RegistryKey
                     regKey = Registry.LocalMachine.OpenSubKey("Software\MyApp", True)
                    regKey.SetValue("Wizard", "1089018919810")
                    regKey.Close()

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: How can i use this code to add registry entry?

    to write to Registry.LocalMachine in vista or win7 you need admin privileges in your app, which requires vb2008+.

    Project-->Properties-->Application-->View UAC Settings + follow the instructions in your app.manifest

    to catch the key combination, set your form's keypreview property to true, then handle the keydown event:

    vb Code:
    1. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    2.     Static ALT_F6_Pressed As Boolean = False
    3.     If e.Modifiers = Keys.Alt AndAlso e.KeyValue = Keys.F6 AndAlso ALT_F6_Pressed = False Then
    4.         ALT_F6_Pressed = True
    5.     ElseIf e.Modifiers = Keys.Alt AndAlso e.KeyValue = Keys.F6 AndAlso ALT_F6_Pressed = True Then
    6.         'edit registry
    7.         ALT_F6_Pressed = False
    8.     End If
    9. End Sub

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How can i use this code to add registry entry?

    Quote Originally Posted by .paul. View Post
    to write to Registry.LocalMachine in vista or win7 you need admin privileges in your app, which requires vb2008+.

    Project-->Properties-->Application-->View UAC Settings + follow the instructions in your app.manifest
    Rather than just making your app run as admin (and meaning the user will get a UAC prompt every time they launch it) I would recommend avoiding storing registry data in HKEY_LOCAL_MACHINE in the first place unless it is absolutely necessary. Use HKEY_CURRENT_USER instead as this does not require admin permissions. The only difference is that registry entries in HKEY_CURRENT_USER will only be visible to the user that is currently logged on - if someone else logs on then they have their own HKEY_CURRENT_USER hive and wont see any changes that were made to that area of the registry whilst another user was logged on. Anything written to HKEY_LOCAL_MACHINE though will be visible to all users no matter which user actually created the value - which is precisely why you need admin permissions to do it.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Uk
    Posts
    157

    Re: [RESOLVED] How can i use this code to add registry entry?

    Thanks Guys, Paul that worked perfectly!

    Just one thing so i know for future reference if i wanted to hit say Alt F6 F6 F6 F6 F6 F6 for the same thing to happen is this possible?

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