SHOW:
|
|
- or go back to the newest paste.
1 | TCHAR szPath[MAX_PATH]; | |
2 | GetModuleFileName(NULL,szPath,MAX_PATH); | |
3 | HKEY newValue; | |
4 | HKEY resKey; | |
5 | subValue = "MyProgram"; | |
6 | RegOpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&newValue); | |
7 | long key = RegQueryValueExA(resKey, subValue, NULL, NULL, NULL, NULL); | |
8 | if(key == ERROR_FILE_NOT_FOUND) | |
9 | { | |
10 | return false; | |
11 | } | |
12 | else | |
13 | - | RegOpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&newValue); |
13 | + | |
14 | - | RegSetValueEx(newValue, subValue ,0,REG_SZ,(LPBYTE)szPath,sizeof(szPath)); |
14 | + | const DWORD cbData = sizeof(TCHAR) * (lstrlen(szPath) + 1); |
15 | RegSetValueEx(newValue, subValue ,0,REG_SZ,(LPBYTE)szPath,cbData); | |
16 | RegCloseKey(newValue); | |
17 | } |