QT实现自动启动(Windows)

QString NMyUtils::getExeFullPathWithArgs()
{
    QString exePath = QCoreApplication::applicationFilePath().replace("/","\\").replace("Reminder.exe","QTLoader.exe");
    QString argPath = "\""+exePath+"\" TrayIcon";
    qDebug()<<argPath;
    return argPath;
}

bool NMyUtils::isAutoStart()
{
    QSettings reg("HKEY_LOCAL_MACHINE\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN", QSettings::NativeFormat);
    QString val = reg.value("NReminder").toString();
    if(val.length()>0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

void NMyUtils::setAutoStart()
{
    QSettings reg("HKEY_LOCAL_MACHINE\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN", QSettings::NativeFormat);
    reg.setValue("NReminder",NMyUtils::getExeFullPathWithArgs());
}

void NMyUtils::removeAutoStart()
{
    QSettings reg("HKEY_LOCAL_MACHINE\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN", QSettings::NativeFormat);
    reg.remove("NReminder");
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*