fork download
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. void AddToAutorun(void)
  5. {
  6. HKEY hKey;
  7. char szPath[MAX_PATH];
  8.  
  9. GetModuleFileName(NULL, szPath, sizeof(szPath));
  10. RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
  11. 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL);
  12. if (hKey)
  13. {
  14. RegSetValueEx(hKey, TEXT("MyAutorunZTRSF"), 0, REG_SZ, (LPBYTE)szPath, lstrlen(szPath));
  15. RegFlushKey(hKey);
  16. RegCloseKey(hKey);
  17. }
  18. }
  19.  
  20. void autorun(void)
  21. {
  22. TCHAR szPath[MAX_PATH];
  23.  
  24. DWORD pathLen = 0;
  25.  
  26. // GetModuleFileName returns the number of characters
  27. // written to the array.
  28. pathLen = GetModuleFileName(NULL, szPath, MAX_PATH);
  29.  
  30. if (pathLen == 0)
  31. return;
  32.  
  33. HKEY newValue;
  34. if (RegOpenKey(HKEY_LOCAL_MACHINE,
  35. TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
  36. &newValue) != ERROR_SUCCESS)
  37. {
  38. printf(TEXT("Unable to open registry key; last error = %lu\n"), GetLastError());
  39. return;
  40. }
  41. // Need to pass the length of the path string in bytes,
  42. // which may not equal the number of characters due to
  43. // character set.
  44. DWORD pathLenInBytes = pathLen * sizeof(*szPath);
  45. if (RegSetValueEx(newValue,
  46. TEXT("name_me"),
  47. 0,
  48. REG_SZ,
  49. (LPBYTE)szPath,
  50. pathLenInBytes) != ERROR_SUCCESS)
  51. {
  52. RegCloseKey(newValue);
  53. printf(TEXT("Unable to set registry value; last error = %lu\n"), GetLastError());
  54. return;
  55. }
  56. RegCloseKey(newValue);
  57. }
  58.  
  59. int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  60. {
  61. AddToAutorun();
  62. autorun();
  63. MessageBox(NULL, TEXT("Hello, World!"), TEXT("Autorun"), MB_OK);
  64. return 0;
  65. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:21: fatal error: windows.h: No such file or directory
compilation terminated.
stdout
Standard output is empty