Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 9th, 2013  |  syntax: None  |  size: 0.55 KB  |  views: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. TCHAR szPath[MAX_PATH];
  2. GetModuleFileName(NULL,szPath,MAX_PATH);
  3. HKEY newValue;
  4. HKEY resKey;
  5. subValue = "MyProgram";
  6.     long key = RegQueryValueExA(resKey, subValue, NULL, NULL, NULL, NULL);
  7.     if(key == ERROR_FILE_NOT_FOUND)
  8.     {
  9.         return false;
  10.     }
  11.     else
  12.     {
  13.       const DWORD cbData = sizeof(TCHAR) * (lstrlen(szPath) + 1);
  14.       RegOpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&newValue);
  15.       RegSetValueEx(newValue, subValue ,0,REG_SZ,(LPBYTE)szPath,cbData);
  16.       RegCloseKey(newValue);
  17.     }