|
Question : Shell batch file and return values
|
|
I would like to SHELL to a batch file, run it, and return a value if successful (copy files from folder to folder). I need to know if the bat file did the job. Is there any code I can add to a bat file to pass back a value that can be examined in VBA (perhaps from the Shell function)?
|
|
Answer : Shell batch file and return values
|
|
You should therefore also be able to use CMD /X to force termination, instead of TerminateProcess():
Const STATUS_PENDING As Long = &H103 Const STILL_ACTIVE As Long = STATUS_PENDING Const PROCESS_QUERY_INFORMATION As Long = &H400
Declare Function CloseHandle _ Lib "kernel32.dll" _ (ByVal hObject As Long) As Long Declare Function GetExitCodeProcess _ Lib "kernel32.dll" _ (ByVal hProcess As Long, _ ByRef lpExitCode As Long) As Long Declare Function OpenProcess _ Lib "kernel32.dll" _ (ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, _ ByVal dwProcId As Long) As Long
Public Sub GetExitCode()
Dim varTaskId As Variant Dim lngProcess As Long Dim lngExitCode As Long
varTaskId = Shell("CMD /C ""C:\Temp\Temp.bat""", vbHide) lngProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, varTaskId) Do DoEvents ' Allow process to complete GetExitCodeProcess lngProcess, lngExitCode Loop While lngExitCode = STILL_ACTIVE CloseHandle lngProcess MsgBox "Exit Code = " & lngExitCode
End Sub
Although it makes no difference either way for me!
|
|
|
|