Saving to Registry after upgrade

L

LDD

Hey folks

I'm upgrading an existing application from VB6 to VB.Net
It's a slow painful process, and there isn't time to rewrite it.
I'm using RegCreateKeyEx(...) to save some data to the registry.
I'm getting Error 1314 and can't seem to find much useful info on this.

If anyone has any information that can help me out that would be great.
Definition:
Public Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias
"RegCreateKeyExA" (ByVal hKey As Integer, ByVal lpSubKey As String, ByVal
Reserved As Integer, ByVal lpClass As String, ByVal dwOptions As Integer,
ByVal samDesired As Integer, ByRef lpSecurityAttributes As
SECURITY_ATTRIBUTES, ByRef lphkResult As Integer, ByRef lpdwDisposition As
Integer) As Integer


Thanks folks

LDD
 
H

Herfried K. Wagner [MVP]

LDD said:
I'm upgrading an existing application from VB6 to VB.Net
It's a slow painful process, and there isn't time to rewrite it.
I'm using RegCreateKeyEx(...) to save some data to the registry.
I'm getting Error 1314 and can't seem to find much useful info on this.

How do you call the function?
 
L

LDD

Here is where it gets called from.

Public Sub gSetRegParamString(ByRef rlHKey As Integer, ByRef rsSubKey As
String, ByRef rsPropertyName As String, ByRef rsPropertyValue As String)

Dim plRC As Integer
Dim plNewHKey As Integer
Dim psSubKey As String
Dim plOpenKey As Integer

'New for create key
Dim plDispositionBuffer As Integer
Dim SA As SECURITY_ATTRIBUTES

RegCreateKeyEx(HKEY_LOCAL_MACHINE, rsSubKey, 0, vbNullString,
REG_OPTION_NON_VOLATILE, KEY_WRITE, SA, plNewHKey, plDispositionBuffer)
.....

End Sub

I know it's something I'm overlooking...

LDD
 
D

Dragon

Hi dude,

Your declaration seems to be OK, however I would use this one:

~
Public Declare Auto Function RegCreateKeyEx Lib "advapi32.dll" ( _
ByVal hKey As IntPtr, _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpSubKey As String,
_
ByVal Reserved As Integer, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal lpClass As StringBuilder, _
ByVal dwOptions As Integer, _
ByVal samDesired As Integer, _
ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _
ByRef phkResult As IntPtr, _
ByRef lpdwDisposition As Integer _
)
~

Anyway, this is a matter of liking.

Are you trying to pass NULL to lpSecurityAttributes? If yes, then you
should include overloaded version of your Declare statement with
lpSecurityAttributes declared as IntPtr and then pass IntPtr.Zero to it.

Error 1314 (ERROR_PRIVILEGE_NOT_HELD) means "A required privilege is not
held by the client.", so you may want to check your rights.

If it doesn't work, provide your SECURITY_ATTRIBUTES declaration please.

HTH,
Roman
 

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