Forum Discussion

Brian Barton's avatar
Brian Barton
Copper Contributor
May 24, 2024

Creating Start Menu Shortcuts to Launch .CMD Files

I am looking to create an MSIX for a custom app. The app is basically dropped in a folder on C:\. I would like to create a Start Menu shortcut in ...Start Menu\Programs\NewApp and have it point to a .CMD file in the installation folder and use an .ico file in that same folder for the icon.

 

Is this doable? Super easy to do with an MSI but I'm challenged to do it in an MSIX.

 

Thanks in advance!

Brian

  • Having a shortcut to the cmd file is possible, but only by using the PSF launcher. But I wouldn't recommend the cmd file be placed at the root of C:\

    Your shortcut (entrypoint) would point to PsfLauncher.exe and the config.json file would then target the cmd file as the program to be run by the launcher.
    • Brian Barton's avatar
      Brian Barton
      Copper Contributor

      TIMOTHY_MANGAN Thanks, I will check out the PSF. The .CMD files won’t be on the root of C:\ but rather in a folder that is on C:\.

      • TIMOTHY_MANGAN's avatar
        TIMOTHY_MANGAN
        MVP
        Maybe OK, but you should change those old habits moving forward. The Windows, Program Files (plurar) and ProgramData folders are better handled when VFS comes into play. If a package needs a script, it should consistently be under Program Files\VendorApp\Scripts so you always know where it is. It's all redirected under WindowsApps anyway, so the user never knows but you'd always know where to look.
  • Peer-Atle's avatar
    Peer-Atle
    Brass Contributor

    Brian Barton 

    You can make a general executable from a ps1 script and include in your MSIX package.
    Use ps2exe to compile script with option noConsole
    Exec.ps1
    if ($args.Count -eq "0"){
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing

    # Create the main form
    $form = New-Object System.Windows.Forms.Form
    $form.Text = "Usage"
    $form.Size = New-Object System.Drawing.Size(350,250)
    $form.StartPosition = "CenterScreen"
    $form.FormBorderStyle = "FixedDialog"

    # Create controls
    $objTextBox1 = New-Object System.Windows.Forms.TextBox
    $objTextBox1.Text = "Exec.exe <Executable> [<Arguments>] [<Workingdir>] [<Min>]"
    $objTextBox1.AppendText("`r`ne.g. Exec.exe Notepad.exe C:\Temp\Inst.log `" `" Min")
    $objTextBox1.AppendText("`r`n")
    $objTextBox1.AppendText("`r`nFirst argument --> Executable")
    $objTextBox1.AppendText("`r`nSecond argument --> Arguments")
    $objTextBox1.AppendText("`r`nThird argument --> Working directory")
    $objTextBox1.AppendText("`r`nFourth argument --> Execute Minimized")
    $objTextBox1.AppendText("`r`n")
    $objTextBox1.AppendText("`r`nArguments MUST come in the correct order")
    $objTextBox1.AppendText("`r`nOmitted arguments can be replaced with `" `"")
    $objTextBox1.AppendText("`r`ne.g. Exec.exe Notepad.exe `" `" C:\Windows")

    $objTextBox1.Multiline = $True

    $objTextBox1.ReadOnly = $True
    $objTextBox1.Location = New-Object System.Drawing.Size(20,20)
    $objTextBox1.Size = New-Object System.Drawing.Size(300,180)
    # $objTextBox1.Scrollbars = "Vertical"
    $form.Controls.Add($objTextBox1)

    # Show the form
    $form.ShowDialog() | Out-Null
    $form.Close() }

    if ($args.Length -eq "1"){
    Start-Process -FilePath $args[0]}

    if ($args.Length -eq "2"){
    Start-Process -FilePath $args[0] -ArgumentList $args[1]}

    if ($args.Length -eq "3"){
    Start-Process -FilePath $args[0] -ArgumentList $args[1] -WorkingDirectory $args[2]}

    if ($args.Length -eq "4"){
    Start-Process -FilePath $args[0] -ArgumentList $args[1] -WorkingDirectory $args[2] -WindowStyle Minimized}

    With MSIX Packaging Tool use PSF Fixup and enable In Package Context

    Package files

    Create AppExecutionAlias in AppxManifest.xml

    Install MSIX and run: ExecExeTemplate_Exec.exe "C:\Inst\List_C.cmd"
    If no arguments are specified: ExecExeTemplate_Exec.exe

     



Resources