How to add a program to startup using WinAPI (C/C++)

Question:

What function, the description of which is in the windows.h header file (as far as I know, it is there), is responsible for autorun and how to register, thanks in advance.

Answer:

HKEY hKey; 
char szPath[0x100]; 
GetModuleFileName(NULL, szPath, sizeof(szPath)); 
RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
                 "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 
                 NULL, 
                 "", 
                 REG_OPTION_NON_VOLATILE, 
                 KEY_SET_VALUE, 
                 NULL, 
                 &hKey, 
                 NULL);

if (hKey) 
{ 
    RegSetValueEx(hKey, "My program", NULL, REG_SZ, (LPBYTE)szPath, strlen(szPath)); 
    RegCloseKey(hKey); 
}
Scroll to Top