Search code examples
pythonvbscriptexe

How can I Make an Executable out of VBS Code?


(Before we begin, just a note that I'm not an experienced coder. This question is a duplicate, however the referred questions are highly outdated, so some things might have changed in the last 10 years.)

I'm attempting to help a project out on GitHub, which asks for an .exe version of a VBS script.
The VBS script in question is this:

Set oShell = CreateObject ("Wscript.Shell") 
oShell.Run "cmd /c python 1fichier-dl/gui.py", 0, false

This basically runs a Python script that makes a GUI for the program.
At first, I looked for a VBS to EXE converter. Programs like VBSedit did not work. I do know that VBS is not a compiled language, but I don't know how to make an equivalent program (in say, Python) that can run a specific program (with a path that is not specifically tied to a users' system).

So, does anyone know

  1. Any other (working) VBS to EXE (or to a compiled language) program that suites my needs?
  2. A code example (in a language like Python) that I can use to execute the program (gui.py, it's in a folder inside the main one named 1fichier-dl)?

Solution

  • Option 1: Create an exe from the Python script using PyInstaller. This, or something similar, must have been used to create the release distribution at https://github.com/manuGMG/1fichier-dl/releases/tag/v0.1.5.

    Option 2: Create a C# console app to launch the Python script. For example:

    using System.Diagnostics;
    
    namespace _1fichier_dl
    {
        class Program
        {
            static void Main(string[] args)
            {
                ProcessStartInfo MyApp = new ProcessStartInfo();
                MyApp.FileName = "pythonw.exe";
                MyApp.Arguments = "1fichier-dl/gui.py";
                Process.Start(MyApp);
            }
        }
    }
    

    Using Visual Studio 2019, create a new Console App (.NET Framework) C# project (give it a name such as 1fichier-dl), select .NET Framework 4.6.1 from the drop down menu and click Create. Once the IDE loads up, paste in the code above (replacing the skeleton code already in the window) and, from the Build menu, select Build Solution. You should find your compiled exe in C:\Users\YourUserName\source\repos.

    Note: This launcher only works if placed in the folder above 1fichier-dl\gui.py and requires pythonw.exe to be on the path.

    Note: The code uses pythonw.exe to hide the Python console. If you want to see the console, change it to python.exe.