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

来自http://tunps.com/registry-autorun-c-code

/*
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>
int main()
{
    LPCSTR regname="Software\\Microsoft\\Windows\\CurrentVersion\\Run";
    HKEY hkResult;
    int ret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
    if(ret != ERROR_SUCCESS)
    {
        printf("error open registry\n");
    }
    ret=RegSetValueEx(hkResult,"hacker",0,REG_EXPAND_SZ,(unsigned char *)"%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);
        return 0;
    }
}

About tunpishuang

just 4 fun·····
This entry was posted in 未分类 and tagged , . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>