Advertisement
Guest User

Untitled

a guest
Apr 9th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. bool function()
  2. {
  3. HKEY hKey;
  4. LPCTSTR subKey;
  5. LPCTSTR subValue;
  6. HKEY resKey;
  7. DWORD dataLen;
  8. hKey = HKEY_CURRENT_USER;
  9. subKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
  10.  
  11. long key = RegOpenKeyExA(hKey, subKey, 0, KEY_READ | KEY_WRITE, &resKey);
  12. if(key == ERROR_SUCCESS)
  13. {
  14. subValue = "MyCoolProgram";
  15. long key = RegQueryValueExA(resKey, subValue, NULL, NULL, NULL, NULL);
  16. if(key == ERROR_FILE_NOT_FOUND)
  17. {
  18. return false;
  19. }
  20. else
  21. {
  22. TCHAR szPath[MAX_PATH];
  23. GetModuleFileName(NULL,szPath,MAX_PATH);
  24. DWORD dataLen = data.size()+1;
  25.  
  26. long key = RegSetValueExA(resKey, subValue, 0, REG_SZ, (LPBYTE)szPath, dataLen);
  27. if(key == ERROR_SUCCESS)
  28. {
  29. return true;
  30. }
  31. else
  32. {
  33. return false;
  34. }
  35. }
  36. }
  37. else
  38. {
  39. return false;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement