[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()
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:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Static ALT_F6_Pressed As Boolean = False
If e.Modifiers = Keys.Alt AndAlso e.KeyValue = Keys.F6 AndAlso ALT_F6_Pressed = False Then
ALT_F6_Pressed = True
ElseIf e.Modifiers = Keys.Alt AndAlso e.KeyValue = Keys.F6 AndAlso ALT_F6_Pressed = True Then
'edit registry
ALT_F6_Pressed = False
End If
End Sub
Re: How can i use this code to add registry entry?
Quote:
Originally Posted by
.paul.
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.
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?