Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET Registers
I am using the following code
 
This error occurs :
 
Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
 

  
 
Public Class FormRegEnumValue
 
Private Const ERROR_SUCCESS = 0&
Private Const ERROR_NO_MORE_ITEMS = 259&
Private Const HKEY_CURRENT_USER = &H80000001
 
Private Const REG_BINARY = 3
Private Const REG_DWORD = 4
Private Const REG_EXPAND_SZ = 2
Private Const REG_SZ = 1
 
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, ByVal lpcbValueName As Long, ByVal lpReserved As Long, ByVal lpType As Long, ByVal lpData As Object, ByVal lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal phkResult As Long) As Long
 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim hKey As Long, num As Long, strName As String
    Dim strData As String, Retval As Long, RetvalData As Long
 
    Const Buffer As Long = 255
    num = 0
    strName = Space(Buffer)
    strData = Space(Buffer)
    Retval = Buffer
    RetvalData = Buffer
    If RegOpenKey(HKEY_CURRENT_USER, "Control Panel\Desktop", hKey) = 0 Then 'error
        While RegEnumValue(hKey, num, strName, Retval, 0, 0&, strData, RetvalData) <> ERROR_NO_MORE_ITEMS
            If RetvalData > 0 Then
                ListBox1.Items.Add(strName + Retval + "  =  " + strData + RetvalData - 1)
            End If
            num = num + 1
            strName = Space(Buffer)
            strData = Space(Buffer)
            Retval = Buffer
            RetvalData = Buffer
        End While
        RegCloseKey(hKey)
    Else
        ListBox1.Items.Add("Error")
    End If
End Sub
End Class
 
 

error in : If RegOpenKey(HKEY_CURRENT_USER, "Control Panel\Desktop", hKey) = 0 Then 'error
I want to use the API
Posted 24-Nov-11 12:53pm
Edited 24-Nov-11 13:22pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hi,
i am not able to get the question completely .All i can get is that you are trying to read a registry entry of Windows using this code and you are getting an error while trying to do so.
just a hint:please check if you have administrative privileges on this machine.
and these might help :
http://msdn.microsoft.com/en-us/library/xz88758e(v=vs.80).aspx[^]
 
http://www.devx.com/vb2themax/Tip/19134[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 255
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 25 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100