Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

RegCreateKeyEx (advapi32)
 
.
Summary
Create or open a registry key

C# Signature:

[DllImport("advapi32.dll", SetLastError=false)]
static extern int RegCreateKeyEx(
            IntPtr hKey,
            string lpSubKey,
            IntPtr Reserved,
            string lpClass,
            RegOption dwOptions,
            RegSAM samDesired,
            ref SECURITY_ATTRIBUTES lpSecurityAttributes,
            out IntPtr phkResult,
            out RegResult lpdwDisposition);

VB Signature:

    <DllImport("advapi32.dll", SetLastError:=False)> _
    Public Function RegCreateKeyEx( _
        ByVal hKey As Integer, _
        ByVal lpSubKey As String, _
        ByVal Reserved As Integer, _
        ByVal lpClass As String, _
        ByVal dwOptions As RegOption, _
        ByVal samDesired As RegSAM, _
        ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _
        ByRef phkResult As Integer, _
        ByRef lpdwDisposition As RegResult) As Integer
    NOT EXECUTABLE!!! PLEASE USE "Microsoft.Win32.Registry" and "Microsoft.Win32.RegistryKey"

User-Defined Types:

    [Flags]
    public enum RegOption
    {
        NonVolatile = 0x0,
        Volatile = 0x1,
        CreateLink = 0x2,
        BackupRestore = 0x4,
        OpenLink = 0x8
    }

    [Flags]
    public enum RegSAM
    {
        QueryValue = 0x0001,
        SetValue = 0x0002,
        CreateSubKey = 0x0004,
        EnumerateSubKeys = 0x0008,
        Notify = 0x0010,
        CreateLink = 0x0020,
        WOW64_32Key = 0x0200,
        WOW64_64Key = 0x0100,
        WOW64_Res = 0x0300,
        Read = 0x00020019,
        Write = 0x00020006,
        Execute = 0x00020019,
        AllAccess = 0x000f003f
    }

    public enum RegResult
    {
        CreatedNewKey = 0x00000001,
        OpenedExistingKey = 0x00000002
    }

Alternative Managed API:

Microsoft.Win32.RegistryKey.CreateSubKey

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions