-1

(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)?
tripleee
  • 175,061
  • 34
  • 275
  • 318
Omega
  • 29
  • 1
  • 6
  • for a python script, just use `subprocess.Popen` to get that cmd line working, then use some string formatting and `pathlib` to get the path you need – Matiiss Aug 25 '22 at 23:35
  • Okay, thanks. I think I have to go learn some more Python for this, though. Does this work for unspecific file paths? – Omega Aug 25 '22 at 23:38
  • you just need to read the documentation and look at some examples, it's not like the syntax's different there... it will work for paths you specify it to work with, look at `pathlib` it provides some great stuff for getting relative paths to users and stuff as well as mostly you'd just use relative paths relative to the cwd – Matiiss Aug 25 '22 at 23:40
  • Not sure why VBSEdit didn't work, but why not write a simple C# program? – LesFerch Aug 25 '22 at 23:47
  • VBSEdit didn't work because using an evaluation copy of the program makes an annoying pop-up saying you have to buy the program to continue using it. I don't want this. I'll be a little more clear; I didn't write the program, the program owner did. I'm learning JS right now, so hopefully when I get that done I can write a program in Python or in C#. I don't know C#, though. – Omega Aug 26 '22 at 00:04
  • 1
    Why do you need a VBS wrapper at all? Just make an EXE of the Python script in question. – tripleee Aug 26 '22 at 08:01
  • 1
    I might try that, @tripleee. I'm just worried that might break something, as the code owner may have made that for something. – Omega Aug 26 '22 at 18:19
  • (Not replying any longer due to the stupidity of this question. Please forget this, because I don't want any more embarrassment than I already have.) – Omega Sep 01 '22 at 04:15

2 Answers2

-1

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.

LesFerch
  • 1,540
  • 2
  • 5
  • 21
-3

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:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\MyApp.exe" "%~dp0\MyApp.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:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\MyApp.exe" "%~dp0\MyApp.vb" /platform:anyCPU`

pause

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

Geert Bellekens
  • 12,788
  • 2
  • 23
  • 50
Lundt
  • 142
  • 1
  • 1
  • 3