Answer the question
In order to leave comments, you need to log in
How to include a program in C++ startup?
I add the program to autoload code:
void AutoRun()
{
char arr[MAX_PATH] = { };
GetModuleFileName(NULL, (LPWSTR)arr, MAX_PATH);
HKEY hKey;
if (RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS)
{
if (RegSetValueEx(hKey, L"My program", NULL, REG_SZ, (LPBYTE)arr, sizeof(arr)) == ERROR_SUCCESS)
{
RegCloseKey(hKey);
}
return;
}
}
Answer the question
In order to leave comments, you need to log in
The last parameter in RegSetValueEx for REG_SZ must be the length of the string + 1 to the terminating null character (strlen(arr)+1) ( https://docs.microsoft.com/en-us/windows/win32/api... )
Do not use MAX_PATH is an ancient, obsolete option. Read until enlightened: https://docs.microsoft.com/en-us/windows/win32/fil...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question