Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Qt Installer Framework - Create shortcut in Start Menu for all users
Qt 6.12 LTS is out! See what's new in the release blog

Qt Installer Framework - Create shortcut in Start Menu for all users

Scheduled Pinned Locked Moved Installation and Deployment
5 Posts 2 Posters 3.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Dear all,

    with the installer framework I would like to create an installer for my application.
    The applicaiton is installed by the administrator on the PC. The application is then used by different users.

    In the installer I create shortcuts from executable to start menu.

    This is accomplished in the installscript.js by the command:
    component.addOperation("CreateShortcut", "@TargetDir@/application.exe", "@StartMenuDir@/Name of Application.lnk", "workingDirectory=@TargetDir@");

    The problem now, is that the installer creates shortcut in the start menu only for the current user, e.g. the Administrator. Also, the uninstall program is visible only for the current user. When I log with another user, the application is not visible in the start menu.

    How is it possible to generate a shortcut, which is visible in the start menu for all users?

    Thank you very much.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Please, I need help on this issue.
      Thx.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        No solution????

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Peter Smithson
          wrote on last edited by Peter Smithson
          #4

          I know this is a little late to reply but this page comes up high in the results when I do a search. Instead of using StartMenuDir, you can use AllUsersStartMenuProgramsPath. The documentation is here - https://doc-snapshots.qt.io/qtifw-master/scripting.html

          Now I've just got to figure out why the icon I've set no longer works when I use that instead of StartMenuDir!

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Peter Smithson
            wrote on last edited by
            #5

            I ended up creating a class to handle this kind of shortcut:

            // QT IFW seems to have a bug. If you use AllUsersStartMenuProgramsPath, it won't then set the icon for the shortcut.
            // This wouldn't be a problem if the target exe had an icon builtin.
            // Also, it ignores the StartMenuDir setting in config.xml.
            
            // This class just does something like this:
            // component.addElevatedOperation("CreateShortcut", `@TargetDir@/${itemName}`,
            //     `@AllUsersStartMenuProgramsPath@/${linkName}.lnk`,
            //     `iconPath=${iconPath}`);
            
            class AllUserShortcut {
                // Constructor method
                constructor(companyName, productName) {
                    this.companyName = companyName;
                    this.productName = productName;
                }
            
                static createFolder(folderPath) {
                    // Create a folder if it doesn't exist and remove it on uninstall if it's empty.
                    var psCreateFolder = `
                    if (-Not (Test-Path -Path "${folderPath}")) {
                        New-Item -ItemType Directory -Path "${folderPath}"
                    }`;
                    var psDeleteEmptyFolder = `
                    if ((Test-Path -Path "${folderPath}") -and (Get-ChildItem -Path "${folderPath}").Count -eq 0) {
                        Remove-Item -Path "${folderPath}"
                    }`;
                    component.addElevatedOperation("Execute", [
                        "powershell.exe",
                        "-ExecutionPolicy", "Bypass",
                        "-Command", psCreateFolder
                    ], "UNDOEXECUTE", [
                        "powershell.exe",
                        "-ExecutionPolicy", "Bypass",
                        "-Command", psDeleteEmptyFolder
                    ]);
                }
            
                createShortcut(itemName, linkName, iconPath) {
                    console.log(`Creating shortcut: ${this.companyName}\\${this.productName}\\${linkName} -> @TargetDir\\${itemName}`);
                    var commonStartMenuDir = installer.environmentVariable("ALLUSERSPROFILE") + "\\Microsoft\\Windows\\Start Menu\\Programs";
            
                    // Create company folder.
                    var companyPath = commonStartMenuDir + `\\${this.companyName}`;
                    AllUserShortcut.createFolder(companyPath);
                    // Create product folder.
                    var productPath = companyPath + `\\${this.productName}`;
                    AllUserShortcut.createFolder(productPath);
            
                    // Use a PowerShell script to create the shortcut with the icon
                    var shortcutPath = productPath + `\\${linkName}.lnk`;
                    var targetPath = installer.value("TargetDir") + `\\${itemName}`;;
            
                    var psScriptContent = `
            $WScriptShell = New-Object -ComObject WScript.Shell
            $Shortcut = $WScriptShell.CreateShortcut("${shortcutPath}")
            $Shortcut.TargetPath = "${targetPath}"`
                    if (iconPath) {
                        psScriptContent += `
            $Shortcut.IconLocation = "${iconPath}"`
                    }
                    psScriptContent += `
            $Shortcut.Save()
                `;
            
                    component.addElevatedOperation("Execute", [
                        "powershell.exe",
                        "-ExecutionPolicy", "Bypass",
                        "-Command", psScriptContent
                    ], "UNDOEXECUTE", [
                        "powershell.exe",
                        "-ExecutionPolicy", "Bypass",
                        "-Command", `Remove-Item -Path "${shortcutPath}" -Force`
                    ]);
                }
            }
            
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt
            • Unsolved