locked
RemoteApp with PowerShell Command RRS feed

  • Question

  • Hey all,

    I am trying to make a tricky thing.

    I know that there is an option to deploy RemoteApp which based batch file, For some reason I can't run this app from a batch and I am able to do that using Powershell with the following command:

    
    Start-Process "\\11.1.1.11\Magic94\mgrntw.exe" "/INI=beitlak\ini\magic.ini /terminal=200 /user=xxxx /password=xxxx /InputPassword=No"
    

    But when I publish a new RemoteApp and then choose Powershell and put this string in the parameters and then trying to open it

    In Remote Gateway, I just getting Powershell empty windows and then it is close automatically, I can't monitor that, it close quickly.

    If I edit the RDP file to text and check the parameters I see this path:

    redirectclipboard:i:1
    redirectprinters:i:1
    redirectcomports:i:0
    redirectsmartcards:i:1
    devicestoredirect:s:*
    drivestoredirect:s:*
    redirectdrives:i:1
    session bpp:i:32
    prompt for credentials on client:i:1
    span monitors:i:1
    use multimon:i:1
    remoteapplicationmode:i:1
    server port:i:3389
    allow font smoothing:i:1
    promptcredentialonce:i:1
    videoplaybackmode:i:1
    audiocapturemode:i:1
    gatewayusagemethod:i:2
    gatewayprofileusagemethod:i:1
    gatewaycredentialssource:i:0
    full address:s:xxxxxxxxx
    alternate shell:s:||powershell (1)
    remoteapplicationprogram:s:||powershell (1)
    gatewayhostname:s:xxxxxxxxxxxxxx
    remoteapplicationname:s:Windows PowerShell
    remoteapplicationcmdline:s:Set-executionPolicy Unrestricted -force; cd \\11.1.1.11\Magic94\; Start-Process "mgrntw.exe" "/INI=beitlak\ini\magic.ini /terminal=200 /user=xxxx /password=xxxx /InputPassword=No"
    workspace id:s:xxxxxxxxxxxxxx
    use redirection server name:i:1
    loadbalanceinfo:s:xxxx

    which is possible to run as copy paste directly to client Powershell.

    Another thing that I tried is - deploy This Powershell as UNC path and when I run it I get this error:

    [Window Title]
    RemoteApp Error

    [Content]
    Couldn’t open this program or file. Either there was a problem with TEST01 or the file you’re trying to open couldn’t be accessed. 
    For assistance, contact your system administrator.

    [OK]

    Any suggestions?


    Windows IT MVP 2015 /2016 www.PelegIT.co.il Thank you!


    • Edited by Meir Peleg Monday, November 27, 2017 8:43 PM
    Monday, November 27, 2017 8:36 PM

Answers

  • Hi,

    What are the reasons you are using PowerShell to launch this app?  Is it simply to have it launch with a specific current directory as well as some command-line parameters?  The reason I ask is, if you don't have complicated logic I would recommend you publish a shortcut (.lnk) to the application instead.

    For example, on the RDSH server(s), you could create a folder named C:\MyApp and inside of this folder create a .lnk file named MyApp.lnk.  In the properties of MyApp.lnk, you would set the fields similar to below:

    Target: \\11.1.1.11\Magic94\mgrntw.exe /INI=beitlak\ini\magic.ini /terminal=200 /user=xxxx /password=xxxx /InputPassword=No 

    Start in: \\11.1.1.11\Magic94\

    Also in the C:\MyApp folder, you would put a copy of the mgrntw.exe file, solely so that RDS can grab the icon from within the exe.  On the broker, you would create the RemoteApp using commands similar to below:

     
    Import-Module RemoteDesktop
    New-RDRemoteApp -CollectionName "MyCollection" -DisplayName "MyApp" -FilePath "C:\MyApp\MyApp.lnk" -ConnectionBroker "MyBroker" -IconPath "C:\MyApp\mgrntw.exe"
     

    If for some reason you must launch an application using a script, for example, you have complex logic that needs to run before the program is launched, the way you can do it is to publish PowerShell.exe as the RemoteApp with command-line parameter set to something like below:

    -ExecutionPolicy Unrestricted -File C:\Windows\System32\MyScript.ps1

    Normal users should only have Read and Execute rights to MyScript.ps1, for security reasons.

    Please reply back with your results and/or any questions you may have.

    Thanks.

    -TP

    • Marked as answer by Meir Peleg Tuesday, November 28, 2017 9:09 PM
    Tuesday, November 28, 2017 8:18 AM

All replies

  • Have you tried generating the remoteapp via powershell and just pointing it to the network shared application directly?

    New-RDRemoteApp -Alias "App Name" -CollectionName "Collection" -DisplayName "APP DisplayName" -FilePath "\\server01\apps\app.exe" -ConnectionBroker connectionbroker.domain.local
    I have a few clients that have shared folder "installed" applications and that's how I get them to run. After you run that cmdlet you can even edit the remoteapp in Server Manager and add the arguments.

    Brian Baldock | MCSA | MS | MCP Please note: This post is provided as is with no guarantee. Test, then test again

    Tuesday, November 28, 2017 2:28 AM
  • The problem is that this EXE file contains some license parameters as I stated above. and it doesn't work

    Windows IT MVP 2015 /2016 www.PelegIT.co.il Thank you!

    Tuesday, November 28, 2017 6:16 AM
  • Hi,

    What are the reasons you are using PowerShell to launch this app?  Is it simply to have it launch with a specific current directory as well as some command-line parameters?  The reason I ask is, if you don't have complicated logic I would recommend you publish a shortcut (.lnk) to the application instead.

    For example, on the RDSH server(s), you could create a folder named C:\MyApp and inside of this folder create a .lnk file named MyApp.lnk.  In the properties of MyApp.lnk, you would set the fields similar to below:

    Target: \\11.1.1.11\Magic94\mgrntw.exe /INI=beitlak\ini\magic.ini /terminal=200 /user=xxxx /password=xxxx /InputPassword=No 

    Start in: \\11.1.1.11\Magic94\

    Also in the C:\MyApp folder, you would put a copy of the mgrntw.exe file, solely so that RDS can grab the icon from within the exe.  On the broker, you would create the RemoteApp using commands similar to below:

     
    Import-Module RemoteDesktop
    New-RDRemoteApp -CollectionName "MyCollection" -DisplayName "MyApp" -FilePath "C:\MyApp\MyApp.lnk" -ConnectionBroker "MyBroker" -IconPath "C:\MyApp\mgrntw.exe"
     

    If for some reason you must launch an application using a script, for example, you have complex logic that needs to run before the program is launched, the way you can do it is to publish PowerShell.exe as the RemoteApp with command-line parameter set to something like below:

    -ExecutionPolicy Unrestricted -File C:\Windows\System32\MyScript.ps1

    Normal users should only have Read and Execute rights to MyScript.ps1, for security reasons.

    Please reply back with your results and/or any questions you may have.

    Thanks.

    -TP

    • Marked as answer by Meir Peleg Tuesday, November 28, 2017 9:09 PM
    Tuesday, November 28, 2017 8:18 AM
  • Hi,

    What are the reasons you are using PowerShell to launch this app?  Is it simply to have it launch with a specific current directory as well as some command-line parameters?  The reason I ask is, if you don't have complicated logic I would recommend you publish a shortcut (.lnk) to the application instead.

    For example, on the RDSH server(s), you could create a folder named C:\MyApp and inside of this folder create a .lnk file named MyApp.lnk.  In the properties of MyApp.lnk, you would set the fields similar to below:

    Target: \\11.1.1.11\Magic94\mgrntw.exe /INI=beitlak\ini\magic.ini /terminal=200 /user=xxxx /password=xxxx /InputPassword=No 

    Start in: \\11.1.1.11\Magic94\

    Also in the C:\MyApp folder, you would put a copy of the mgrntw.exe file, solely so that RDS can grab the icon from within the exe.  On the broker, you would create the RemoteApp using commands similar to below:

     
    Import-Module RemoteDesktop
    New-RDRemoteApp -CollectionName "MyCollection" -DisplayName "MyApp" -FilePath "C:\MyApp\MyApp.lnk" -ConnectionBroker "MyBroker" -IconPath "C:\MyApp\mgrntw.exe"
     

    If for some reason you must launch an application using a script, for example, you have complex logic that needs to run before the program is launched, the way you can do it is to publish PowerShell.exe as the RemoteApp with command-line parameter set to something like below:

    -ExecutionPolicy Unrestricted -File C:\Windows\System32\MyScript.ps1

    Normal users should only have Read and Execute rights to MyScript.ps1, for security reasons.

    Please reply back with your results and/or any questions you may have.

    Thanks.

    -TP

    Hey,

    The script worked!

    Thanks for sharing this!!


    Windows IT MVP 2015 /2016 www.PelegIT.co.il Thank you!

    Tuesday, November 28, 2017 9:09 PM
  • Hey again

    I have installed another RDSH server with RemoteApp and publish the same application as I did with the previous one, the main difficulty over here is when I am open the application on the new server with Administrator credential everything works, however, when opening it with regular domain users I get this:

    There are normal permissions as I did a comparison between servers but can't solve it yet.

    familiar with this issue guy?>

    [Window Title]
    RemoteApp Error

    [Content]
    The program did not start on the remote computer.
    For assistance, contact your system administrator.

    [OK]


    Windows IT MVP 2015 /2016 www.PelegIT.co.il Thank you!

    Wednesday, December 6, 2017 10:04 AM
  • Hi Meir,

    Yes, I have run into that.  If using .lnk or script, normally it is permissions issue either relating to the .lnk/.ps1/.cmd file and/or the target .exe.  In most cases checking share and ntfs permissions I will find the cause.

    Worst case I do a quick procmon trace and the source of the issue becomes clear.

    -TP

    Thursday, December 7, 2017 8:36 AM
  • Hey there,

    Thanks for replying me, it couldn't be a permission issue, I have created a new Remote App with the same location where it is already worked on the different terminal server.

    However, the customer does not want it anymore.

    Thank you, guys.


    Windows IT MVP 2015 /2016 www.PelegIT.co.il Thank you!

    Monday, December 11, 2017 6:29 AM