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.
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
n1mdas
Posts: 22
Last visit: Sat Dec 05, 2020 2:51 pm

call external *.exe on click within GUI app

Post by n1mdas »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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: 22
Last visit: Sat Dec 05, 2020 2:51 pm

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

Post by n1mdas »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

There is no more detail. Just use the code to see how it works.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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: 22
Last visit: Sat Dec 05, 2020 2:51 pm

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

Post by n1mdas »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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

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

or:
Start-Process mfile.exe -wait
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

n1mdas wrote: Sun Jan 14, 2018 10: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: 22
Last visit: Sat Dec 05, 2020 2:51 pm

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

Post by n1mdas »

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.
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked