0

I want to open a WPF application from remote machine using PowerShell. This is the command I'm using

   Invoke-Command -ComputerName "ComputerNamne" -ScriptBlock { & "C:\...App.exe" } -credential "Username"

but for some reason nothing happens

I was able to start the process when calling batch file which calls the applcation

Invoke-Command -ComputerName "ComputerNamne" -ScriptBlock { & "C:\...RubApp.bat" } -credential "Username"

but in this way the GUI is not appearing. I can see in task manager that the app is running though.

So two questions:

  1. Why can't I run directly the exe file?
  2. Why the GUI is hidden in the second method. Can I solve this?
Tsahi
  • 445
  • 4
  • 22
  • Here's different ways to start program in powershell: http://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx . I would use Start-Process (start/saps) –  Dec 19 '16 at 15:38
  • 4
    You can't run a graphical app from `invoke-command` or other WinRM methods. If you want to do that, look into using `psexec` with the `-i` switch – BenH Dec 19 '16 at 15:42
  • @maximdumont, you can run graphical apps using this method? – Tsahi Dec 19 '16 at 15:45
  • Thanks @BenH. I'll look into it – Tsahi Dec 19 '16 at 15:48
  • Start-Process doesn't run on remote computers. Wrapping it in `invoke-command` will run you into the same issues. The ways you can make it "work" with a `invoke-command` would be scheduling a task or creating start-up script – BenH Dec 19 '16 at 15:48
  • @BenH, Are you sure the I can run GUI application using psexec ? I'm getting the same behavior. Task is created in task manager but not UI? Command: PsExec \\machine -i -d "C:\..App.exe" – Tsahi Dec 19 '16 at 16:09
  • 1
    Try adding the console id after `-i`. If you are trying to display in console session 2, you would use: `PsExec \\machine -i 2 -d "C:\..App.exe"` – BenH Dec 19 '16 at 18:00
  • @BenH, Adding console id did the trick :) – Tsahi Dec 20 '16 at 06:21

2 Answers2

1

For invoking GUI app , you have to use PSexec with -i :

You can download it from here and you will get to know how to use also. PSTools Download

Hope it helps.

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
0

I concur with Ranadip on this one. This is not a feature of powershell, as neither WinRM nor WMI will allow you to utilize a GUI application remotely.

See a similar question: Running remote GUI app in Powershell

Community
  • 1
  • 1
DeepS1X
  • 344
  • 3
  • 12