设置Qt程序在Windows开机后自动运行

2020-11-24 01:07

阅读:647

标签:blog   tar   http   c   string   art   

(转自:http://blog.csdn.net/weiren2006/article/details/7443362)

 

让软件在系统启动时自动运行,可通过修改注册表实现。

在\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run中添加需启动的程序路径,代码如下:

 

voidautoStart(boolflag)
{
//写入注册表,开机自启动
HKEYhKey;
//找到系统的启动项
LPCTSTRlpRun=(wchar_t*)QString("Software\\Microsoft\\Windows\\CurrentVersion\\Run").utf16();
//打开启动项Key
longlRet=RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpRun,0,KEY_WRITE,&hKey);
if(lRet==ERROR_SUCCESS)
{
DWORDdwRet=QApplication::applicationFilePath().length()*2;
//添加一个子Key,并设置值
if(flag==true)
{
lRet=RegSetValueEx(hKey,(WCHAR*)QString("test").utf16(),0,REG_SZ,
(BYTE*)QApplication::applicationFilePath().utf16(),dwRet);
}
else
{
lRet=RegSetValueEx(hKey,(WCHAR*)QString("test").utf16(),0,REG_SZ,
(BYTE*)"",dwRet);
}
//关闭注册表
RegCloseKey(hKey);
if(lRet!=ERROR_SUCCESS)
{
qDebug("error");
}
}
}

设置Qt程序在Windows开机后自动运行,搜素材,soscw.com

设置Qt程序在Windows开机后自动运行

标签:blog   tar   http   c   string   art   

原文地址:http://www.cnblogs.com/FindSelf/p/3716741.html


评论


亲,登录后才可以留言!