title: How to use RegCreateKeyEx?
body: <p>I have a question about using <code>RegCreateKeyEx</code> in C++.
  When I'm trying to create a key under HKLM - it does not work,
  but other situation(creating the key at the HKCU) - it does work well (can create key).</p>
  
  <p>My OS is win7 x86 - does it matter when using <code>RegCreateKeyEx</code>? </p>
  
  <p>The code I'm running is the following:</p>
  
  <pre><code>#include&lt;Windows.h&gt;
  #include&lt;stdio.h&gt;
  
  int main()
  {
      HKEY hKey;
      LONG result = 0;
      char filename[] = "C:\test.jpg";
      char *path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\test";
  
      if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &amp;hKey, NULL) == ERROR_SUCCESS)
          printf("1. success \n"); // ← doesn`t work 
      else printf("fail\n");
  
      if (RegCreateKeyEx(HKEY_CURRENT_USER, "Console\papadaks", 0, NULL,       
              REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &amp;hKey, NULL) == ERROR_SUCCESS)
          printf("2. success \n");  // ← works well 
      else printf("fail\n");
  
      return 0;
  }
  </code></pre>
  
  <p>Thanks.</p>