将程序加入注册表开机启动[C代码]

/*
code by tunpishuang
vc++ 2008编译通过
使用“使用多字节字符集”,而非Unicode
功能:
在HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run中加入自启动项目hacker,
数据类型REG_EXPAND_SZ,数据值:%systemroot%\hacker.exe
*/
#include <windows.h>
#include <stdio.h>
intmain()
{
LPCSTRregname=”Software\\Microsoft\\Windows\\CurrentVersion\\Run”;
HKEYhkResult;
intret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
if(ret != ERROR_SUCCESS)
{
printf(“error open registry\n”);
}
ret=RegSetValueEx(hkResult,”hacker”,0,REG_EXPAND_SZ,(unsignedchar*)”%systemroot%\\hacker.exe”,25);

if(ret==0){
printf(“success to write run key\n”);
RegCloseKey(hkResult);
}
else{
printf(“failed to open regedit.%d\n”,ret);
return0;
}
}

标签: C语言, Windows API, 注册表

添加新评论