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.