| | |
Registry Permissions
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2008
Posts: 324
Reputation:
Solved Threads: 7
Error is coming Registry Access is not allowed.While Opening a Key.
Can Somebody help me out.
Can Somebody help me out.
VB.NET Syntax (Toggle Plain Text)
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click NewDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Sonia") End Sub Private Sub NewDelete(ByVal KeyPath As String, ByVal KeyName As String) Dim sMainKey As String Dim sKeyPath As String Dim ObjReg As RegistryKey Dim sData As Object Try Dim mSec As New RegistrySecurity() Dim user As String = Environment.UserDomainName & "\" & Environment.UserName sMainKey = Mid(KeyPath, 1, InStr(KeyPath, "\", Microsoft.VisualBasic.CompareMethod.Text) - 1) ObjReg = GetMainKey(sMainKey) sKeyPath = Replace(KeyPath, sMainKey, "") Do While True If Mid(sKeyPath, 1, 1) = "\" Then sKeyPath = Mid(sKeyPath, 2) Else Exit Do End If Application.DoEvents() Loop Dim rule As New Security.AccessControl.RegistryAccessRule(user, _ Security.AccessControl.RegistryRights.FullControl, _ Security.AccessControl.AccessControlType.Allow) mSec.AddAccessRule(New RegistryAccessRule(user, RegistryRights.FullControl, _ System.Security.AccessControl.InheritanceFlags.ContainerInherit, _ PropagationFlags.None, AccessControlType.Allow)) ObjReg = ObjReg.OpenSubKey(sKeyPath, True) ObjReg.SetAccessControl(mSec) If ObjReg IsNot Nothing Then ObjReg.Close() mSec.AddAccessRule(rule) 'if Object .Equals ( If Not ObjReg Is Nothing Then sData = Registry.GetValue(ObjReg.ToString, KeyName, "") If Not sData Is "" Then ObjReg.DeleteValue(KeyName, False) End If End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub
Running on Vista?
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
•
•
Join Date: Mar 2008
Posts: 324
Reputation:
Solved Threads: 7
VB.NET Syntax (Toggle Plain Text)
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim a As RegistryPermission = New RegistryPermission( _ RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Sonia") a.Demand() NewDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Sonia", "ss") End Sub Private Sub NewDelete(ByVal KeyPath As String, ByVal KeyName As String) Dim sMainKey As String Dim sKeyPath As String Dim ObjReg As RegistryKey Dim sData As Object Try sMainKey = Mid(KeyPath, 1, InStr(KeyPath, "\", Microsoft.VisualBasic.CompareMethod.Text) - 1) ObjReg = Registry.LocalMachine sKeyPath = Replace(KeyPath, sMainKey, "") Do While True If Mid(sKeyPath, 1, 1) = "\" Then sKeyPath = Mid(sKeyPath, 2) Else Exit Do End If Application.DoEvents() Loop ObjReg = ObjReg.OpenSubKey(sKeyPath, True) If Not ObjReg Is Nothing Then sData = Registry.GetValue(ObjReg.ToString, KeyName, "") If Not sData Is "" Then ObjReg.DeleteValue(KeyName, False) End If End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub
Last edited by Ancient Dragon; Jan 23rd, 2009 at 7:03 pm. Reason: add code tags
To run as administrator
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
LOL, I got it, I don't know, they may understand my question wrong
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
- trojans wont let me connect to internet (Viruses, Spyware and other Nasties)
- Vista Registry permissions and owner gone (Windows Vista and Windows 7)
- urllogic, downloader-va??? (Viruses, Spyware and other Nasties)
- help with hjt and vx2/urllogic (Viruses, Spyware and other Nasties)
- HijackThis shows 01 entries - can't remove (Viruses, Spyware and other Nasties)
- 213.159.117.130 trojan.. help!! (Viruses, Spyware and other Nasties)
- deleting registry key for error code 19 (Windows NT / 2000 / XP)
Other Threads in the VB.NET Forum
- Previous Thread: Coding Problem
- Next Thread: ISBN 10/13 validation and conversion
Views: 1006 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 2008 access add application array assignment basic box button buttons center class click code combo convert cpu data database datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees error excel exists firewall function image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan picturebox port print printing printpreview problem record refresh regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase storedprocedure string structures studio temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet vista visual visualbasic visualbasic.net visualstudio2008 web wpf xml






