Qt5程序开机自启动(windows)

简介

window下开机启动最简单的实现方式就是在注册表中添加启动项目 添加位置有两个
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

 

第一个为全局自动启动项,所有用户登陆后都自动启动。第二个为当前用户启动项、切换到其他用户就失效了

代码

void appAutoRun(bool bAutoRun)
{
    //HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
    QSettings  reg("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",QSettings::NativeFormat);

    if (bAutoRun)
    {
        reg->setValue("wirtepad",QCoreApplication::applicationFilePath());
    }
    else
    {
        reg->setValue("wirtepad","");
    }

}

提示

win7以后权限管理越来越严格,非管理员权限运行的程序是无法写入到HKEY_LOCAL_MACHINE下的,推荐添加启动项到当前用户
 
 http://blog.csdn.net/x356982611/article/details/53183144

 

posted @ 2016-01-12 18:41  findumars  Views(1435)  Comments(0Edit  收藏  举报