1
votes

Please help me run an external command from VB6:

I need to run the command

java  –jar  run.jar

Under the following directory:

C:\Program Files\MY_SW_PROD\last\Java_sw

run.jar is inside the java_sw directory but my VB6 application is not.

I have the following code but it doesn't work because I am not inside the java_sw directory:

   Shell Environ("COMSPEC") & " /c  java  –jar  run.jar", vbNormalFocus

How do I change to the correct directory C:\Program Files\MY_SW_PROD\last\Java_sw, so that I will able to run the run.jar file?

Remark - ChDir isnt working on WIN XP !

1

1 Answers

1
votes

Use the VB6 function ChDir to change the current working directory, prior to your Shell:

Dim currentDirectory as String

'Get the current working directory
currentDirectory = CurDir("C:")
'Change the current working directory
Call ChDir("C:\Program Files\MY_SW_PROD\last\Java_sw")
'Do you shell stuff here.

'Then set the current directory to the starting value
Call ChDir(currentDirectory)

(It's also good practice to set it back to the original value: use CurDir to store the current working directory).

If you want the command window to stay open, use /K instead of /C for CMD.exe.