Good morning,

I'm having some difficulties fixing a problem, I need to allow permissions for a user to change the wallpaper but i can't seem to get it to work, i hope you can help me. :)

Here's the code :

Dim RespostaMess As MsgBoxResult = MsgBox("Tem a certeza que quer mudar a imagem?", MsgBoxStyle.YesNo)
        Dim rs As New RegistrySecurity
        Dim user As String = Environment.UserDomainName & "\" & Environment.UserName
        Dim AbreChave As RegistryKey = Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", True)
        Try
            rs.AddAccessRule(New RegistryAccessRule(user, RegistryRights.ReadKey Or RegistryRights.SetValue Or RegistryRights.WriteKey, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow))
            AbreChave.SetAccessControl(rs)
        Catch ex As Exception
            MsgBox("AbreChave " & ex.Message.ToString)
        End Try
        GetValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", True)
        If FundoIComboBox.Text = "Esticar" Then
            Style = DStyle.Stretch
        End If
        If FundoIComboBox.Text = "Mosaico" Then
            Style = DStyle.Tiled
        End If
        If FundoIComboBox.Text = "Centrar" Then
            Style = DStyle.Center
        End If
        If RespostaMess = MsgBoxResult.No Then
            ChangeWallpaper(GetValue)
        End If
        If RespostaMess = MsgBoxResult.Yes Then
            ChangeWallpaper(OpenFileDialog1.FileName.ToString)
            MsgBox("A imagem foi inserida com sucesso.")
            Try
                rs.AddAccessRule(New RegistryAccessRule(user, RegistryRights.SetValue Or RegistryRights.WriteKey, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Deny))
                AbreChave.SetAccessControl(rs)
            Catch ex As Exception
                MsgBox("Abrechave fecha " & ex.Message.ToString)
            End Try
        End If

Some parts are in Portuguese, but i'll translate...
"Tem a certeza que quer mudar a imagem?" --> Are you sure you wish to change the wallpaper?
"Esticar" --> Stretch
"Centrar" --> Centered
"Mosaico" --> Tiled
"A imagem foi inserida com sucesso." --> The wallpaper was inserted with success.

Unfortunately, I think it's more than a permissions issue based on what I saw at this link and this search

Well i was able to change it manually through regedit, but i had to do a number of steps, and they are:

1. Change the wallpaper key's path.
2. Allow permission to all users to read the value in the wallpaper key.
3. reboot.

And it worked fine, i don't know why, but the code i have should've worked.
I'm trying to do those steps but in code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.