PDA

View Full Version : Problem creating Registry Keys - VB.NET CF 1.x


BongoUser
25th January 2007, 10:38 AM
Hi, if i create a registry key i get an NonSupportet Exception.
Can someone Help?

Here the important part of my code:


Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0

Private Declare Function RegCreateKeyEx Lib "coredll.dll" Alias "RegCreateKeyExW" ( _
ByVal hkey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As String, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
ByRef phkResult As Long, _
ByRef lpdwDisposition As Long) As Long

Public Shared Function CreateNewKey(ByVal lSection As Long, _
ByVal sNewKeyName As String) As Long

Dim hNewKey As Long
Dim lRetVal As Long
RegCloseKey(lSection)
--HERE--> lRetVal = RegCreateKeyEx(lSection, sNewKeyName, 0, _
vbNullString, REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
0, hNewKey, lRetVal)

CreateNewKey = hNewKey

RegCloseKey(hNewKey)

End Function


...

i call for example:
CreateNewKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Today\Items\""Wireless""" )


Please help.
Thanks.

dotfred
25th January 2007, 01:29 PM
Hi, if i create a registry key i get an NonSupportet Exception.
Can someone Help?

Here the important part of my code:


Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0

Private Declare Function RegCreateKeyEx Lib "coredll.dll" Alias "RegCreateKeyExW" ( _
ByVal hkey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As String, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
ByRef phkResult As Long, _
ByRef lpdwDisposition As Long) As Long

Public Shared Function CreateNewKey(ByVal lSection As Long, _
ByVal sNewKeyName As String) As Long

Dim hNewKey As Long
Dim lRetVal As Long
RegCloseKey(lSection)
--HERE--> lRetVal = RegCreateKeyEx(lSection, sNewKeyName, 0, _
vbNullString, REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
0, hNewKey, lRetVal)

CreateNewKey = hNewKey

RegCloseKey(hNewKey)

End Function


...

i call for example:
CreateNewKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Today\Items\""Wireless""" )
Please help.
Thanks.
Hi,


1) I wouldn't use lRetVal for the last parameter and the return function value. The last parameter returns the disposition value and the function return value returns 0 for success or an error that you can find in WINERROR.H and so in MSDN documentation.


If it is not the problem then:

2) In place of trying to create a key in HKLM, try first in HKCU, maybe the problem doesn't reside in the code but in the fact that you are trying to create a key in HKLM where you need "authorization" to do it. Your application needs to have privileges like being signed.

Hope it helps,

Cheers,

.Fred

ps.: use a real program language like C/C++. VB is crap!!! ;):D

BongoUser
25th January 2007, 02:53 PM
Hi,


1) I wouldn't use lRetVal for the last parameter and the return function value. The last parameter returns the disposition value and the function return value returns 0 for success or an error that you can find in WINERROR.H and so in MSDN documentation.


If it is not the problem then:

2) In place of trying to create a key in HKLM, try first in HKCU, maybe the problem doesn't reside in the code but in the fact that you are trying to create a key in HKLM where you need "authorization" to do it. Your application needs to have privileges like being signed.

Hope it helps,

Cheers,

.Fred

ps.: use a real program language like C/C++. VB is crap!!! ;):D


Hi,

it works nowm thanks.
I have found a working sample in www.