How to delete a registry key, after getting values (in Windows mobile 6)


B

bkoron

How to delete a registry key, after getting values (in Windows mobile 6)

Hi! I am working on a project in Windows mobile 6 which read keys and values
and then delete some registry keys. But after getting values from a
registry key and then try to delete,i got an Unauthorized exception. Please
help me ASAP.


Here is a part of my code

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CODE FOR GETTING VALUES FROM A REGISTRY KEY

Dim ProfileReg As Microsoft.Win32.Registry
Dim CountForList As Long, ContactId As String
Dim ListIT As ListView.ListViewItemCollection = ContactLIST.Items
Dim ValueNames As String(), OnceValue As String
Try
ValueNames =
ProfileReg.CurrentUser.OpenSubKey("Software\Microsoft\CF\" &
ProfileComBox.SelectedItem.ToString, True).GetValueNames()
ProfileReg.CurrentUser.Close()
If ValueNames.Length <= 0 Then ProfileReg.CurrentUser.Close() :
ProfileHasChanged = False : Exit Sub
System.Windows.Forms.Application.DoEvents()

For Each OnceValue In ValueNames
For CountForList = 0 To ContactLIST.Items.Count - 1
ContactId =
ListIT.Item(CountForList).SubItems.Item(1).Text()
If ContactId = OnceValue Then
ContactLIST.Items.Item(CountForList).Checked = True
Exit For
End If
Next
Next
ProfileReg.CurrentUser.Close()
ValueNames.Clear(ValueNames, 0, ValueNames.Length)
ProfileHasChanged = False

Catch ex As Exception
Msgbox ex.message
End Try

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

CODE WHICH DELETE A REGISTRY KEY

Private Sub ProfileDelBut_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ProfileDelBut.Click

Dim RegKey As RegistryKey
Dim NameOfOldProfile As String = ProfileComBox.Text '.ToString
Dim Key As String = "Software\Microsoft\CF\" ' & NameOfOldProfile

Try
ProfileReg.CurrentUser.Close() ' IN CASE I FORGOT TO CLOSE
THE REGISTRY KEY
RegKey = ProfileReg.CurrentUser.OpenSubKey(Key, True) 'Key

RegKey.DeleteSubKeyTree(NameOfOldProfile)
' EVEN IF I TRY THIS, I STILL HAVE UnauthorizedAccessException
RegKey.DeleteSubKey(NameOfOldProfile)
ProfileReg.CurrentUser.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly,
"error")
ProfileReg.CurrentUser.Close()
End Try
End Sub
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top