Hello, I have a problem with a registry value and button text set in vb.net i would like that when i press button, the value in registry change and also the button text Code: Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim EtatNotification As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Activation", "NotificationDisabled", "") If EtatNotification = "1" AndAlso My.Settings.Langue = "Français" Then BtnActiverDesactiverNotifications.Text = "Activer Les Notifications D'Activation De Windows" ElseIf EtatNotification = "1" AndAlso My.Settings.Langue = "Anglais" Then BtnActiverDesactiverNotifications.Text = "Enable Windows Activation Notifications" ElseIf EtatNotification = "0" AndAlso My.Settings.Langue = "Français" Then BtnActiverDesactiverNotifications.Text = "Désactiver Les Notifications D'Activation De Windows" ElseIf EtatNotification = "0" AndAlso My.Settings.Langue = "Anglais" Then BtnActiverDesactiverNotifications.Text = "Disable Windows Activation Notifications" End If End Sub Code: Private Sub BtnActiverDesactiverNotifications_Click(sender As System.Object, e As System.EventArgs) Handles BtnActiverDesactiverNotifications.Click If Me.Text = "Désactiver Les Notifications D'Activation De Windows" Then Call DésactiverNotificationsWindows() BtnActiverDesactiverNotifications.Text = "Activer Les Notifications D'Activation De Windows" ElseIf Me.Text = "Disable Windows Activation Notifications" Then Call DésactiverNotificationsWindows() BtnActiverDesactiverNotifications.Text = "Enable Windows Activation Notifications" ElseIf Me.Text = "Activer Les Notifications D'Activation De Windows" Then Call ActiverNotificationsWindows() BtnActiverDesactiverNotifications.Text = "Désactiver Les Notifications D'Activation De Windows" ElseIf Me.Text = "Enable Windows Activation Notifications" Then Call ActiverNotificationsWindows() BtnActiverDesactiverNotifications.Text = "Disable Windows Activation Notifications" End If End Sub Code: Private Function ActiverNotificationsWindows() Dim autoshell = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Activation", True) autoshell.SetValue("NotificationDisabled", 0) autoshell.Close() End Function Code: Private Function DésactiverNotificationsWindows() Dim autoshell = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Activation", True) autoshell.SetValue("NotificationDisabled", 1) autoshell.Close() End Function This is a screen to see more clearly
Take a look here: http://forums.mydigitallife.net/threads/33138-VB-NET-Modify-a-reg-key?p=566780&viewfull=1#post566780 You can add the button text also for the result.. No need for all these functions.. You can also use the CurrentCulture.Name function for language. You could simply call this sub: Code: Public Sub Notifications() Try Dim Lm As RegistryKey = Registry.LocalMachine Dim Notification As RegistryKey = Lm.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Activation", RegistryKeyPermissionCheck.ReadWriteSubTree, Security.AccessControl.RegistryRights.SetValue Or Security.AccessControl.RegistryRights.QueryValues) Dim Enabled As Nullable(Of Integer) = CType(Notification.GetValue("NotificationDisabled"), Nullable(Of Integer)) If Enabled <> 1 Then Notification.SetValue("NotificationDisabled", 1, RegistryValueKind.DWord) Button1.Text = "Disable" Else Notification.SetValue("NotificationDisabled", 0, RegistryValueKind.DWord) Button1.Text = "Enable" End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub
or u coud take a look at my help thread that shows EXACTLY how to change reg value- it's in my signature as the onestop simple help thread
?, then why is he asking how to change the value then, btw could u take a look at my thread on overlay EDIT: o i see he has similar code in his functions as to my tutorial, oops ahah
thanks you very much, im gonna stop using this as a chat thread, although his problem seems to be solved
Ok, all works ! Thanks you very much ! I could change the value of my key but I couldn't change the button text after changing... Thanks it's very cool, so this is my code : Code: Try Dim Lm As RegistryKey = Registry.LocalMachine Dim Notification As RegistryKey = Lm.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Activation", RegistryKeyPermissionCheck.ReadWriteSubTree, Security.AccessControl.RegistryRights.SetValue Or Security.AccessControl.RegistryRights.QueryValues) Dim Enabled As Nullable(Of Integer) = CType(Notification.GetValue("NotificationDisabled"), Nullable(Of Integer)) If Enabled <> 1 AndAlso My.Settings.Langue = "Français" Then Notification.SetValue("NotificationDisabled", 1, RegistryValueKind.DWord) BtnActiverDesactiverNotifications.Text = "Activer Notifications Windows" ElseIf Enabled <> 1 AndAlso My.Settings.Langue = "Anglais" Then Notification.SetValue("NotificationDisabled", 1, RegistryValueKind.DWord) BtnActiverDesactiverNotifications.Text = "Enable Windows Activation Notifications" ElseIf Enabled <> 0 AndAlso My.Settings.Langue = "Français" Then Notification.SetValue("NotificationDisabled", 0, RegistryValueKind.DWord) BtnActiverDesactiverNotifications.Text = "Désactiver Notifications Windows" ElseIf Enabled <> 0 AndAlso My.Settings.Langue = "Anglais" Then Notification.SetValue("NotificationDisabled", 0, RegistryValueKind.DWord) BtnActiverDesactiverNotifications.Text = "Disable Windows Activation Notifications" End If Catch ex As Exception MsgBox(ex.Message) End Try But I have a little question, can you explain me what does it mean this lines : Code: Dim Notification As RegistryKey = Lm.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Activation", RegistryKeyPermissionCheck.ReadWriteSubTree, Security.AccessControl.RegistryRights.SetValue Or Security.AccessControl.RegistryRights.QueryValues) Dim Enabled As Nullable(Of Integer) = CType(Notification.GetValue("NotificationDisabled"), Nullable(Of Integer)) Bye Bye and thanks a lot !