In this article, I will demonstrate how to build an EXE to run your PowerShell scripts with WinRAR. You will learn how to create an EXE using the WinRAR GUI, and automate this task using PowerShell.

Creating an EXE using WinRAR ^

WinRAR is known to compress or decompress files. Although this is the most common use of this tool, it also offers other functionalities. One of these is to create a self-extracting archive (SFX) with an EXE extension. Using this method allows you to choose a file that will be launched after running your EXE file and set an icon to your EXE file.

Let’s see how to build the EXE with the help of the WinRAR GUI.

Consider the following configuration for the step by step guide and script used in this article:

  • ps1 > Script to launch when we run the EXE
  • ico > Icon for our EXE file
  • My first EXE > Name of our EXE file
  • %temp% > Path where our EXE will be extracted
  1. You start by opening WinRAR and click on the Wizard button.
    Click the Wizard button

    Click the Wizard button

  2. Select the file to run using the EXE > MyScript.ps1
  3. Check the option Create a new archive
    Create a new archive button

    Create a new archive button

  4. Type your EXE name > My first EXE
    Type your EXE name

    Type your EXE name

  5. Check the option “Create a self-extracting (.exe) archive
    Create self-extracting archive

    Create self-extracting archive

  6. The EXE will be created on your desktop. It isn’t yet ready to run our ps1 file, it’ll just extract it.
  7. To that end open the My_first_EXE.exe file with WinRAR and click the SFX button.
  8. Then select the Comment tab and copy the text below in the comment field
    Comment tab

    Comment tab

    Comment text

  9. Let’s add an icon to our EXE file. This can be achieved by clicking on the Advanced SFX options.
    Advanced SFX option

    Advanced SFX option

  10. Then click the Text and Icon tab and the Browse button for Load SFX icon from this file.
    Text and icon tab

    Text and icon tab

    Load SFX icon from the file

    Load SFX icon from the file

  11. Once it’s done, the EXE below is created on your desktop.
    EXE file

    EXE file

Automating the EXE creation with PowerShell ^

The next script allows you to automate the tasks mentioned earlier: (a) create an SFX archive, (b) apply the comment part to the EXE file and (c) attribute an icon to our EXE file.

In this script we will use the same configuration as in the script above:

  • PS1 script to launch > ps1
  • Icon for the EXE > ico
  • EXE name > My first EXE

To use the comment part, create a “.conf” file that contains the comment part mentioned above. This file will be stored in the variable $My_Conf_File.

Note: Remove the setup part below from the .conf file. It will be added using the script.

Setup=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -sta -WindowStyle Hidden -noprofile -executionpolicy bypass -file %temp%\MyScript.ps1

The following variables will also be used:

  • $Temp_Folder > Path to your temp folder
  • $User_Profile > Path to the current user profile
  • $Global:User_Desktop > Path to the current user desktop
  • $Global:Winrar_Folder > Path to your WinRAR folder
  • $Global:Temp_Conf_file > Temp conf file which will be created to add the commandline

This script will proceed as below:

  • Copies your .conf file in %temp%
  • Adds the command line to run the ps1 file you have typed
  • Creates the SFX archive and set the icon file

At your administrative command prompt, type the required information.

Your EXE information

Your EXE information

As you can see in the following screenshot, after entering the EXE information, the process will start.

EXE has been created

EXE has been created



See more options using rar.exe /?

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!

0
Share
5 Comments
  1. JimmyDerp 4 years ago

    Can you create a self-extracting Powershell script to create a self-extracting Powershell script?

    "yo dawg I heard you like self-extracting Powershell scripts so we created a Powershell script that self-extracts and creates a self-extracting Powershell script that extracts itself and creates a self-extracting Powershell script!"

    2+

  2. wand3rvogel 4 years ago

    Discover free 7z SFX module by Oleg N. Scherbakov:

    http://www.7zsfx.info/en/examples.html

    0

  3. Rory 3 years ago

    Nice one! I did something similar with 7-zip a few years ago. Had some apps that third party consultants needed and provided the company VPN software the same way.

    0

  4. aaa 1 year ago

    Just correcting a minor mistake

    r = Repair archive

    -r = Recurse subdirectories

    0

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2020

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account