C++添加开机自启动的代码 发表于 2018-01-17 | 123456789101112131415161718192021222324252627282930313233343536373839404142#include <stdio.h>#include <Windows.h>#include <string.h>int main() { char regname[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"; TCHAR path[] = "C:\\Windows\\System32\\door.exe"; HKEY hKey; int ret; ret = RegOpenKey(HKEY_LOCAL_MACHINE, regname, &hKey); ret = RegSetValueEx(hKey, "door", 0, REG_EXPAND_SZ, (unsigned char *)path, strlen(path)); if (ret == ERROR_SUCCESS) { printf("success to write run key\n"); RegCloseKey(hKey); } else { printf("fail to set value. %d\n", ret); system("pause"); return 0; } char modlepath[256]; char syspath[256]; GetModuleFileName(NULL, modlepath, 256); //printf("%s\n", modlepath); GetSystemDirectory(syspath, 256); //printf("syspath:%s\n", syspath); ret = CopyFile(modlepath, strcat(syspath, "\\door.exe"), 1); if (true) { printf("%s has been copy to %s", modlepath, syspath); } else { printf("the file is exist"); } //system("pause"); return 0;} 效果 打赏专区 打赏 微信支付 支付宝 本文作者: giantbranch 本文链接: https://www.giantbranch.cn/2018/01/17/C++添加开机自启动的代码/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!