[VB.NET] Problem with changing button text and set registry value

Discussion in 'Mixed Languages' started by BaWFrAgOr, May 2, 2012.

  1. BaWFrAgOr

    BaWFrAgOr MDL Novice

    Jul 31, 2011
    17
    1
    0
    #1 BaWFrAgOr, May 2, 2012
    Last edited by a moderator: Apr 20, 2017
    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
    Capture.jpg
     
  2. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,886
    20,247
    180
    #2 Alphawaves, May 2, 2012
    Last edited by a moderator: Apr 20, 2017
    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..:eek:
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,886
    20,247
    180
    I think he's already figured that one out steve..;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #5 stevemk14ebr, May 3, 2012
    Last edited: May 3, 2012
    ?, 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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,886
    20,247
    180
    He looks like hes already got the reg value edit.. Will look at your thread now..
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    thanks you very much, im gonna stop using this as a chat thread, although his problem seems to be solved
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. BaWFrAgOr

    BaWFrAgOr MDL Novice

    Jul 31, 2011
    17
    1
    0
    #8 BaWFrAgOr, May 3, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    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 ! :biggrin:
     
  9. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,886
    20,247
    180
    #9 Alphawaves, May 4, 2012
    Last edited: May 4, 2012
    Gives you Registry Rights for whatever your doing, also gets result of Enabled. :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...