Hi everyone!

I'm new to visual basic and i have been using it shortly.

I need a code which will help me compile an exe file based on some arguments or with the help of another VB file.

Thank you.

Dani AI

Generated

A concise, practical summary for the original request from : the problem in this thread splits into two different goals — (A) packaging an existing binary as a different EXE-like artifact, and (B) actually producing/compiling a new executable from code at runtime. Below are three reliable, production-ready approaches (tied to the VB families discussed by , , , and ), with concrete steps and a short VB.NET example for invoking a compiler process.

  1. External compile (VB.NET / modern .NET projects)
  • Generate the .vb source files (or a .vbproj) into a temp folder.
  • Run the Visual Basic compiler or the build tool from the app and capture stdout/stderr. The Visual Basic command-line compiler is documented here. How to invoke vbc.exe. For project builds prefer MSBuild or the dotnet CLI; MSBuild and dotnet-msbuild are documented here. MSBuild reference. dotnet msbuild / dotnet build.

Example (VB.NET): run vbc or msbuild and capture output.

Dim psi As New ProcessStartInfo("vbc.exe")
psi.Arguments = "-out:Generated.exe ""C:\temp\GeneratedModule.vb"""
psi.RedirectStandardOutput = True
psi.RedirectStandardError = True
psi.UseShellExecute = False
psi.CreateNoWindow = True

Using p As Process = Process.Start(psi)
    Dim out = p.StandardOutput.ReadToEnd()
    Dim err = p.StandardError.ReadToEnd()
    p.WaitForExit()
    Dim code = p.ExitCode
End Using
  1. In-process compilation (no external process)
  • Use the .NET Compiler Platform (Roslyn) to build a VisualBasicCompilation, then call Emit() to produce an EXE or DLL at runtime. This avoids launching vbc/msbuild and is suitable for VB.NET code generation scenarios. See the Roslyn APIs and VisualBasicCompilation documentation. Roslyn / VisualBasicCompilation.Create.
  1. Legacy VB6 projects
  • The supported command-line route is to call the VB6 IDE with its /make switch (requires VB6 on the build machine and has known quirks). Example usage and notes are available in community docs and build guides. VB6 /make examples.

Cautions: compiler locations and behavior depend on installed tooling (Visual Studio, Build Tools, .NET SDK); modern SDK-style projects should use dotnet build rather than invoking legacy vbc directly. Also consider signing, antivirus/AV false-positives, and file-system/privilege constraints when emitting executables at runtime. Visual Basic command-line notes (dotnet build).

Recommended Answers

All 12 Replies

? are you asking how to build your project into an exe? or have a curent vb application build a new executable?

I think he/she is referring on creating an EXE file but compiling it first.

If you create an EXE file of your VB Project, VB automatically compiles it and stops if there are any error on your program.

To check for errors more accurately, hit CTRL + F5 rather than just F5 (for testing purposes after each coding).

If this is what you mean that is.

I need a code which will help me compile an exe file based on some arguments or with the help of another VB file

Rather use the "Package and Deployment" wizard that came with VB^ to compile your app.:)

It will refer back to errors if there are any, or compile if all is fine. Don't try and re-invent the wheel if it already exists.

? are you asking how to build your project into an exe? or have a curent vb application build a new executable?

I need to have a current vb app to build a new executable...

I'm not sure what it is exactly that you need to do here? Firstly, you needed to know how to compile an application, now you need an application. I'm confused...

Give us some more information please.:)

Ok. Let me make things clear......
There are some apps like WinRar and Winzip that can make exe files (on runtime) with options given by the user.
Is it possible to do something similar in Visual Basic or should I download some reference dll?

some apps like WinRar and Winzip that can make exe files

They do not create .exe files, only compress/decompress EXISTING .exe files.

If you want to compile an .exe, you need to get an installer app, of which VB6 has the
"Package and Deployment" wizard.

If you want to compress/decompress files, use winzip or winrar's dll files in your code.

They do not create .exe files, only compress/decompress EXISTING .exe files.

Not true. There is a setting to create the archive as an EXE file. When you execute this file the archive is decompressed automatically. Not sure exactly how they do it, though. I assume they have the 'exe' file front end that the archive is appended to as a data segment.

I'll have to delft into this a bit more, will see what time permits tomorrow. I have checked my version (fairly new) and I have no option to zip into an exe though.

Will post a solution if I can tomorrow.:)

Have you considered the possibility of having a previously compiled program that uses a data file, or perhaps the Registry, to get information that would be entered when your programs are installed? Just a thought ...

are you saying, in the installation windows (like windows installer), the user can check options upfront, and the executable is built based on those selections?

or are you saying, inside a vb6 program that you have, you want to allow the user to select options, and build another exe based on what they entered in the first application?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.