Hi Dw I'm glad to find one active VB forum for the old VB I used to get the solutions in .NET and I'm also a .NET developer but had got a problem the computer that I'm creating this application for is using old Windows OS such as XP and the most of them uses Windows 2000 so the .NET application is not supported so I'm recreating this application in VB 5.0.

The program is simple it just execute a jar (java) file using a console and wait for the user to choose the exit option which closes the whole console so here is how to call it manually in a cmd.exe
Java.exe -jar c:\test/dist/test.jar
That is all I want to call so is there anyone know how can I, I'm sorry but as I've said I'm a .NET developer I don't know how to start or where to start in VB5.0 so your help will be appreciated.

Thank you.

Dani AI

Generated

Good troubleshooting by — starting a JAR from VB5 is simple, but a few practical details make it reliable across XP/2000 machines and let you pass arguments, wait for the process, or capture output.

Build a properly quoted command line (quote every path or argument that may contain spaces), and remember JVM options come before -jar while program arguments follow the JAR name. Example pattern for constructing the command string in VB5:

' build a safe command line (quote paths and args)
javaPath = "C:\Program Files\Java\jre6\bin\java.exe"
jarPath  = "C:\test\dist\test.jar"
arg1     = "argument with spaces"
cmdLine  = """" & javaPath & """ -Xmx256m -jar """ & jarPath & """ """ & arg1 & """"

To run synchronously (wait until the Java program exits) and optionally capture output, use Windows Script Host from VB5 rather than the raw Shell call. WScript.Shell has both Run (simple, returns exit code when you wait) and Exec (gives StdOut/StdErr streams). Example usage:

Set wsh = CreateObject("WScript.Shell")
exitCode = wsh.Run(cmdLine, 1, True)   ' window style = 1, True = wait for return
' or use wsh.Exec(cmdLine) to read StdOut while it runs

Troubleshooting notes: if java.exe isn't found, either use the full JRE path or read the JavaHome from the registry (HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion → JavaHome); set the child process working directory (ChDrive/ChDir in VB before launch or use CreateProcess) if the JAR expects relative files; use java (console) vs javaw (no console) depending on whether you need the console; and wrap any argument that contains spaces in quotes. If you need maximum control (handles, exit code, current directory), use the native CreateProcess/WaitForSingleObject approach instead of WSH.

Well I've just managed to solve this problem I've used this
Call Shell("Java.exe -jar c:\test/dist/test.jar") and it debugged well Thanks to my self for this.

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.