Veras, yo tuve una necesidad similar, y te dejo aqui el código del módulo que utilizo desde hace unos años y hasta ahora funciona a la perfección.
Código vb:
Ver originalOption Explicit
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const HIGH_PRIORITY_CLASS = &H80
Private Const INFINITE = -1&
Public Function ExecCmd(cmdline As String) As Long
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
start.cb = Len(start)
start.dwFlags = &H1
start.wShowWindow = 0
ret = CreateProcessA(0&, cmdline, 0&, 0&, 1&, HIGH_PRIORITY_CLASS, 0&, 0&, start, proc)
'Espera a que finalice la aplicación lanzada y devuelve su código de error
ret = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret
End Function
En mi caso, la siguiente funcion forma parte del módulo pero fue por mi necesidad, puede servirte de ejemplo, esto es lo que debes adaptar a tu sistema:
Código vb:
Ver originalPublic Function ErrorDeNIF(ByVal QueNif As String) As Integer
Dim Retorno As Long
Retorno = ExecCmd("java -jar valnif.jar " & QueNif)
Select Case Retorno
Case Is = 0: ErrorDeNIF = 0 ' Correcto
Case Is = 1: ErrorDeNIF = 1 ' Incorrecto o no encontró valnif.jar
Case Is = -1: ErrorDeNIF = 2 ' Java no se ha ejecutado
End Select
End Function
Espero te sirva tanto como a mi
Saludos