RegCreateKeyEx functionality, specify class(object type) of a key, with .NET?

S

Saby

The RegCreateKeyEx() API provides a parameter to specify the
class(object type) of the a key. (lpClass in the definition below)

LONG RegCreateKeyEx(
HKEY hKey,
LPCTSTR lpSubKey,
DWORD Reserved,
LPTSTR lpClass,
DWORD dwOptions,
REGSAM samDesired,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
PHKEY phkResult,
LPDWORD lpdwDisposition
)

The RegistryKey class in the .NET framework do not provide this
functionality.
How do I do this in .NET?
 
R

Randy Charles Morin

Truth. I've never seen someone use that parameter and don't even know
what it does.

Solution. You could write a interop function that calls the
RegCreateKeyEx Win32 API directory.

Hope this helps,

Randy
http://www.kbcafe.com
 
S

Saby

Thanks.
I used the following... Works great.

[DllImport("advapi32.dll")]
public static extern int RegCreateKeyEx(
uint hKey,
string lpSubKey,
int Reserved,
string lpClass,
int dwOptions,
int samDesired,
ref int lpSecurityAttributes,
ref uint phkResult,
ref int lpdwDisposition
);

uint hKey = 0;
int disp = 0;
int reserved = 0;
int ret = 0;
uint root = 0x80000002; //HKLM
ret = SomeClass.RegCreateKeyEx(root, "SOFTWARE\\test1", 0,
"Parameter", 0,0,ref reserved, ref hKey, ref disp);
 

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