Qt创建开机启动快捷方式和桌面启动快捷方式

    //建立桌面快捷方式
    QString strAppPath = "C:/UpdateApp/MyProcess.exe";//要创建快捷方式的应用程序绝对路径
    QString strDesktopLink = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/";
    strDesktopLink += "MyProcess.lnk";
    //判断是否已存在
    QFileInfo  dir0(strDesktopLink);
    if (dir0.isFile())
    {
        QFile::remove(strDesktopLink);
    }
    //生成桌面快捷方式
    QFile fApp(strAppPath);
    fApp.link(strDesktopLink);

    //建立开机启动快捷方式
    QString strMenuLink = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/"; 
    strMenuLink += "Startup/";
    QDir pathDir;
    pathDir.mkpath(strMenuLink);
    strMenuLink += "MyProcess.lnk";

    //判断是否已存在
    QFileInfo  dir(strMenuLink);
    if (dir.isFile())
    {
        QFile::remove(strMenuLink);
    }
    //生成开机启动快捷方式
    fApp.link(strMenuLink);

//效果如下

Qt创建开机启动快捷方式和桌面启动快捷方式_第1张图片

你可能感兴趣的:(QT5)