PS1 To Exe Generator - New version
https://www.systanddeploy.com/2017/11/ps1-to-exe-generator-new-version.html
In this post, I will show you the new version of my tool PS1 To EXE generator that allows you to generate an EXE file from a PowerShell project, choose the main ps1 and inlude other files and folders.
In this new version, there is some new features:
- New design
- Possibility to require or not admin rights for your EXE
- Possibility to set a password
- Possibility to add paramaters to your PS1 script
- Check WinRAR informations
Prerequisites
The EXE file is an SFX archive build with WinRAR meaning Winrar is required.
Even if WinRar prompts you for a licence, it's not mandatory, you can still use it :-)
Known issue
Your EXE may be connsidered as a Trojan by your antivirus.
In fact it's false positive report.
See below some articles about this subject:
https://thesunstroke.blogspot.com/2017/11/false-antivirus-reports-on-installers.html
https://www.virusbulletin.com/virusbulletin/2005/11/false-positive-disaster-anti-virus-vs-winrar-amp-co/
Other ways
There are plenty ways to build an EXE but for most of them you have to pay.
There is also another very cool solution called PS2EXE. However with this solution you can only create an EXE from one PS1 file, meaning you can not build a project with a PS1 that will run other files.
In my case I build WPF tools that need some assemblies, meaning PS2EXE can not help me.
How to get the tool ?
How it looks like ?
The tool is now composed of two parts.
The first part allows you to select your EXE options, name, icon, path...
The second part will check if Winrar is installed or not.
How to use it ?
1 / Run the PS1 To EXE Generator.exe or run the PS1 located in the Sources folder as below:
2 / Select your PowerShell project. This project should be the folder containing your PS1 file.
3 / Type the name of the EXE.
4 / Choose the main PS1 file that will be run after running the EXE file.
5 / Choose an icon if needed
6 / Click on the Build the EXE button to create your EXE.
7 / Once it's done the below message appears and your EXE file will be created in your Desktop.
More options
Admin rights
In the EXE configuration part, the Requires admin rights CheckBox allows you to ask or not admin rights after running the EXE.
Set a Password
This function allows you to ask for a password after running the EXE.
Click on the button in the title bar and check the set a password checkbox, as below:
Now when you run your EXE, you will have to type your password as below:
If a bad password is typed, you will get the below message
Add parameters
Click on the More options button in the title bar, as above.
In the Add parameters to your PS1 TextBox, type the parameters to add. Don't forget to type with "-"
Tool in action
- I want to build an EXE to run a PowerShell tool.
- The PS1 that will launch the tool is called BIOS_Checker.ps1
- The folder containing the PS1 is like below:
See below the tool in action
See below the EXE in action
1 commentaire
Hi!!!
I was having issues running the PS1ToEXE_Generator.ps1 because the DLL's wasn't been loaded:
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///R:\MahApps.Metro.dll' or one of its dependencies. The system cannot find
the file specified."
At C:\Users\F09348\Desktop\PS2EXE\New_Version\Sources\Sources\PS1ToEXE_Generator.ps1:12 char:1
+ [System.Reflection.Assembly]::LoadFrom('MahApps.Metro.dll') ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///R:\MahApps.Metro.IconPacks.dll' or one of its dependencies. The system
cannot find the file specified."
At C:\Users\XXXXXXX\Desktop\PS2EXE\New_Version\Sources\Sources\PS1ToEXE_Generator.ps1:13 char:1
+ [System.Reflection.Assembly]::LoadFrom('MahApps.Metro.IconPacks.dll') ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
Exception calling "Load" with "1" argument(s): "Could not find file 'R:\PS1ToEXE_Generator.xaml'."
At C:\Users\XXXXXXX\Desktop\PS2EXE\New_Version\Sources\Sources\PS1ToEXE_Generator.ps1:18 char:5
+ $XamlLoader.Load($filename)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
I suggest you to update use the variable $PSScriptRoot to create a full path
Look:
[System.Reflection.Assembly]::LoadFrom($PSScriptRoot + '\MahApps.Metro.dll') | out-null # <<<< Here
[System.Reflection.Assembly]::LoadFrom($PSScriptRoot + '\MahApps.Metro.IconPacks.dll') | out-null # <<<< Here
and
$XamlMainWindow=LoadXml($PSScriptRoot + "\PS1ToEXE_Generator.xaml") # <<<< Here
Enregistrer un commentaire