Thread: creating a reg value...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    creating a reg value...

    well I have mastered delteing a reg key. Now I want to create a reg key value. Not a key but a value under an already existing key.

    Here is my code...

    Code:
    const BYTE* &a = "Comp Cleaner (Alex).exe\0"
        
        RegSetValueEx(
        HKEY_CURRENT_USER,
        "\Software\\Microsoft\\Windows\\CurrentVersion\\Run\0",
        0,
        REG_SZ,
        &a,
        sizeof &a
        );
    I have the headers and int main father up in the code. I didn't bother puting them in, I have windows.h and all of those.

    Here is the code MSDN gave me...


    Code:
    LONG RegSetValueEx(
      HKEY hKey,
      LPCTSTR lpValueName,
      DWORD Reserved,
      DWORD dwType,
      const BYTE* lpData,
      DWORD cbData
    );

    So how exactly do I do this?

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    easy this is one of my old code... anyway you should try to SEARCH in the forum before asking such a already-asked question

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main()
    {
        HKEY hKey;
        DWORD dwDisposition;
        char szData[50]="C:\\filename.exe";
    
        RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
        RegSetValueEx(hKey, "mykey", 0, REG_SZ, (LPBYTE)szData, sizeof(szData));
        RegCloseKey(hKey);
    
        return 0;
    
    }
    This forum is the best one I've ever seen. Great ppl, great coders

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    well yoru code doesn't work. Even with about 40 mins of trieng so many different things.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    what errors do you have in your log?

    It works for me.

    Let see what's wrong with you, post your log after compiling it.
    This forum is the best one I've ever seen. Great ppl, great coders

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok so It did work. But...OMG! I just figured it out. It was creting them under the local machine! I wanted it under current user. Well... Thanks guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Creating a rain effect...
    By Raigne in forum Game Programming
    Replies: 11
    Last Post: 12-04-2007, 05:30 PM
  3. Help creating lists of pointers
    By The_Kingpin in forum C Programming
    Replies: 2
    Last Post: 12-11-2004, 08:10 PM
  4. Creating a Simple DLL in C
    By Ultima4701 in forum C Programming
    Replies: 2
    Last Post: 11-23-2002, 01:01 PM
  5. mswinsck.ocx to reg
    By Commander in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 07-09-2002, 06:08 AM