call external *.exe on click within GUI app

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
n1mdas
Posts: 6
Joined: Thu Dec 28, 2017 2:05 pm

call external *.exe on click within GUI app

Post by n1mdas » Thu Jan 11, 2018 12:08 pm

Hello,

Sapien Studio 2017: 5.4.145 running on Windows 7 Pro SP1 Retail x64.

I am working on a PowerShell GUI portable app. Most of the scripts were created under MainFunctions.ps1 and I import them before a specific usage scenario. I have some scripts that were *.vbs and converted them to *.exe. I want the PowerShell GUI to be portable with elevated manifest - here ok so the customer for example copies the GUI app to a folder with writable permissions and so forth -- all fine here. I understood that the packager does not support embedding other executables and unpacking them at runtime, because type of behavior is often flagged as virus behavior and frowned upon by Microsoft. Microsoft’s prescribed method is to use *.MSI installers.

Let's say I will provide the customer 2x files *.exe - signed etc.. one will be the GUI app and the *.VBS -> *.EXE that can be run when clicking on a button.

What I need as a suggestion is how to execute / run the *.exe file from a current dir when a button within the GUI app is clicked?

I found this but as far I know and understand this works for scripts only.

viewtopic.php?t=10327

User avatar
jvierra
Posts: 12101
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: call external *.exe on click within GUI app

Post by jvierra » Thu Jan 11, 2018 12:28 pm

PowerShell studio can generate MSI installers and deploy extra files.

To run an EXE in PowerShell just state the name of the EXE.

c:\folder\myapp.exe

This will execute the exe.

Note that PowerSHell can directly execute VBS files. Those files can be stored inside of PS as a text block.

$vbscript = @'
... vbs code here
...
@'
This can be executed with the VBS COM object as a string.

User avatar
n1mdas
Posts: 6
Joined: Thu Dec 28, 2017 2:05 pm

Re: call external *.exe on click within GUI app

Post by n1mdas » Thu Jan 11, 2018 3:38 pm

Can you jvierra point me to both options with more detailed examples for both options?

Thank you in advance for the quick feedback reply on this matter.

User avatar
jvierra
Posts: 12101
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: call external *.exe on click within GUI app

Post by jvierra » Thu Jan 11, 2018 3:41 pm

There is no more detail. Just use the code to see how it works.

User avatar
jvierra
Posts: 12101
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: call external *.exe on click within GUI app

Post by jvierra » Thu Jan 11, 2018 5:26 pm

Here is an old Sapien blog post on how to run VBScript in PowerShell:

https://www.sapien.com/blog/2009/09/15/ ... powershell
link to examples: Download Invoke-ActiveScript wrapper and demos

User avatar
n1mdas
Posts: 6
Joined: Thu Dec 28, 2017 2:05 pm

Re: call external *.exe on click within GUI app

Post by n1mdas » Sun Jan 14, 2018 11:25 am

Hello,

First of all thanks for both options. Having in mind these:

https://www.sapien.com/blog/2009/09/15/ ... owershell/
Link to examples: Download Invoke-ActiveScript wrapper and demos

I will build the *.exe options for both x64 and x86 as in the example above I need to have the *.vbs option to rebuild the prerequisite option with the Functions etc. in order to meet it. .I thought there is an easy option to "run" it $vbs = @' vbs code '@ and not to rewrite all the *.vbs like it is described in the article.

Anyways..

Is there are best practice example to include within the click action to wait until the *.exe application is finished and go to the next action ?

Is this a good option what I want to accomplish:

$StartApplication = "Path_to\exe\aplication.exe"
Start-Process -FilePath $StartApplication -wait
Wait-Job $StartApplication
[void][System.Windows.Forms.MessageBox]::Show("The application $StartApplication is being executed", 'Please wait the completion of the application')
.. next action..

I would like to show a msgbox that will notify the user that the application will run and then the next steps will be proceeded . Currently the *.exe runs on the test machine for 1 min and 30 seconds upon completion. How to accomplish this?

Thanks

User avatar
jvierra
Posts: 12101
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: call external *.exe on click within GUI app

Post by jvierra » Sun Jan 14, 2018 11:43 am

Start-Process c:\test\myscript.vbs -wait

Or:
Start-Process cscript -Argument c:\test\myscript.vbs -wait

or:
Start-Process mfile.exe -wait

User avatar
jvierra
Posts: 12101
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: call external *.exe on click within GUI app

Post by jvierra » Sun Jan 14, 2018 11:50 am

n1mdas wrote:
Sun Jan 14, 2018 11:25 am
I would like to show a msgbox that will notify the user that the application will run and then the next steps will be proceeded . Currently the *.exe runs on the test machine for 1 min and 30 seconds upon completion. How to accomplish this?
You are asking for us to design your form for you. That is your responsibility. To design a form you must be proficient in both PowerSHel and Windows Forms.

Here is a good resource to get you started: Learn PowerShell

Also this is a very good tutorial and reference: https://www.sapien.com/books_training/W ... werShell-4

User avatar
n1mdas
Posts: 6
Joined: Thu Dec 28, 2017 2:05 pm

Re: call external *.exe on click within GUI app

Post by n1mdas » Sun Feb 11, 2018 11:06 am

Hello and thanks for the suggestions.
I would like to show a msgbox that will notify the user that the application will run and then the next steps will be proceeded . Currently the *.exe runs on the test machine for 1 min and 30 seconds upon completion. How to accomplish this?
I was more looking for a "best practice" one but found some other suggestions here within the forum :) .

I will build the *.exe options for both x64 and x86 as in the example above I need to have the *.vbs option to rebuild the prerequisite option with the Functions etc. in order to meet it. .I thought there is an easy option to "run" it $vbs = @' vbs code '@ and not to rewrite all the *.vbs like it is described in the article.

Thanks for the help.

Locked