Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool function()
- {
- HKEY hKey;
- LPCTSTR subKey;
- LPCTSTR subValue;
- HKEY resKey;
- DWORD dataLen;
- hKey = HKEY_CURRENT_USER;
- subKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
- long key = RegOpenKeyExA(hKey, subKey, 0, KEY_READ | KEY_WRITE, &resKey);
- if(key == ERROR_SUCCESS)
- {
- subValue = "MyCoolProgram";
- long key = RegQueryValueExA(resKey, subValue, NULL, NULL, NULL, NULL);
- if(key == ERROR_FILE_NOT_FOUND)
- {
- return false;
- }
- else
- {
- TCHAR szPath[MAX_PATH];
- GetModuleFileName(NULL,szPath,MAX_PATH);
- DWORD dataLen = data.size()+1;
- long key = RegSetValueExA(resKey, subValue, 0, REG_SZ, (LPBYTE)szPath, dataLen);
- if(key == ERROR_SUCCESS)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- else
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement