include files inside of .EXE or .MSI

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 1 month and 3 weeks 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
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

include files inside of .EXE or .MSI

Post by mqh77777 »

I've been playing around with .MSI creation within PowerShell Studio. Under Settings \ Files-Folders I've pointed to an .EXE that displays a GUI. Under Settings \ Custom Actions I've pointed to the .EXE and used the INSTALLDIR default. I've said to Run at Installation. In my script I've tried using the & sign to point to the .EXE.

It never runs. Can you embed an .EXE within your compiled .MSI (or EXE) and have it install when the .MSI is run? Or will this only with if you have your script first copy the .exe down to the system and then run it from there?
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: include files inside of .EXE or .MSI

Post by Alexander Riedel »

There is no limitation on what types of files you can include in an MSI. If an exe file installed by the MSI installer, it usually is either a system limitation or a setting on the custom action.
So the exact settings you use and the version of PowerShell Studio used as well as OS information would all be helpful to diagnose the issue.
Additionally, running your installer with logging would also tell you why a custom action was not performed.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: include files inside of .EXE or .MSI

Post by mqh77777 »

Product: PowerShell Studio 2018 (64 Bit)
Build: v5.5.155
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17763.0

Target machines are all Windows 10 - 1709. Local PowerShell version on each Windows 10 workstation is 5.1
Within the Script of my Form do I need to call the .EXE I want to run? i.e.
$form1_Load={
& .\MyCustom.exe}
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: include files inside of .EXE or .MSI

Post by Alexander Riedel »

That really depends on when you want it to run. By using a custom action it seemed you want to run it on install.
If you run it from the load event it launches obviously each time your app is started.
I cannot tell from your post what you are actually trying to do. Each way serves a purpose of course, but I cannot tell which one would be best for you.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: include files inside of .EXE or .MSI

Post by mqh77777 »

on the custom actions I have 4 different ways to run it.
Immediately
When the system is being modified (deferred)
During installation rollback
After the system as been successfully modified (commit)

How do you run it on the Load Event? Do you mean when the Form Loads?
$form1_Load={
& .\MyCustom.exe}

This is what I already asked.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: include files inside of .EXE or .MSI

Post by Alexander Riedel »

I would refer you to this article for more information on custom actions: https://www.sapien.com/blog/2018/02/26/ ... i-builder/
If you are trying to run a file that is part of your MSI, 'Immediately' won't work, since that is done before files are copied.
Generally 'commit' is the safest bet unless you have a good reason for any other time.

As for executing your custom exe from the event handler, using ./ is almost always a bad idea. There is no guarantee that the current folder is the same as where your application resides.
It can be anything and if you have shortcuts on a desktop, the user can also set it to something else easily.
I would recommend to always use the full path and obtaining the path to the hosting script or exe using the Get-ScriptDirectory snippet.

I would also use this code
  1. if($LASTEXITCODE -eq 0)
  2. {
  3.     Write-Host "The last PS command executed successfully"
  4. }
  5. else
  6. {
  7.     Write-Host "The last PS command failed"
  8. }
to determine if the program was executed correctly.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: include files inside of .EXE or .MSI

Post by mqh77777 »

Yes, I had found that same web page. I now have this working (almost) I can make it run my .EXE when I install the .MSI which is very cool but only if the .EXE is already on the machine. It has to be in c:\temp\ for the .MSI to see it. I tried to add the file within the .MSI but it never gets copied down to the c:\temp.

files / folder - Files (drag and drop files here)
c:\temp\desktop_manager.exe

Custom Action - Properties
file = c:\temp\desktop_manager.exe
Folder = INSTALLDIR
execution time = after the system has been successfully modified (commit)
execution options = none

when I compile this shouldn't it compile the c:\temp\desktop_manager.exe within the .MSI file?
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: include files inside of .EXE or .MSI

Post by Alexander Riedel »

Please do not use the term 'compile'. It just creates confusion. You package a script to make an exe (that is also not a compiler). Or you build/create/make an MSI.
The term "to compile" in this context means to translate source code into binary machine instructions or at least ILASM (Intermediate Language ASeMbly), both of which do not apply here.

"when I compile this shouldn't it compile the c:\temp\desktop_manager.exe within the .MSI file?"
The MSI builder will add any file to your installer that you specify. If you do not add it, no, it will not add it just because you call it somewhere.

If you add your file from C:\Temp\DesktopManager.exe it does not mean that the installer will copy it to that location. That is not how installers operate.
The files you add are collected from the location you specify, but will be copied on the target machine to the specified install folder.
So your 'C:\Temp\DesktopManager.exe' will end up in 'C:\Program Files\<your product>\DesktopManager.exe. Assuming your target folder is under "C:\Program Files".

This may help you as well:
https://www.sapien.com/blog/2024/01/17/ ... r-install/
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 month and 3 weeks 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