How can I Make an Executable out of VBS Code?

Question:

(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)?
Asked By: Omega

||

Answers:

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:UsersYourUserNamesourcerepos.

Note: This launcher only works if placed in the folder above 1fichier-dlgui.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.

Answered By: LesFerch

Any other (working) VBS to EXE (or to a compiled language) program
that suites my needs?

  1. Delete the word set from the code.

  2. Add a line above the set command line – Dim oShell As Object.

  3. Add four lines at the top of your file.

    Imports System

    Imports System.Runtime.InteropServices

    Public Module Whatever

    Sub Main

  4. Add two lines to the end of the file

    End Sub

    End Module

  5. Put in a batch file in same folder.

"C:WindowsMicrosoft.NETFrameworkv4.0.30319vbc.exe" /target:exe /out:"%~dp0MyApp.exe" "%~dp0MyApp.vb" /verbose /platform:anyCPU

pause

It is simple to compile VBSCRIPT.

Put in to myapp.vb.

Imports System`

Imports System.Runtime.InteropServices`
    
Public Module Whatever`
    
    Sub Main`

        Dim oShell As Object

        oShell = CreateObject ("Wscript.Shell") 

        oShell.Run "cmd /c python 1fichier-dl/gui.py", 0, false

      End Sub`

End Module`

Then put in a batch file

"C:WindowsMicrosoft.NETFrameworkv4.0.30319vbc.exe" /target:exe /out:"%~dp0MyApp.exe" "%~dp0MyApp.vb" /platform:anyCPU`

pause

Here is a few VBScript compiled https://winsourcecode.blogspot.com/search/label/VBScript%20ported%20to%20VB.NET

Answered By: Lundt
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.