|
-
Jul 7th, 2000, 08:42 AM
#1
Thread Starter
Lively Member
I am having to run a batch file to communicate with an AS400 (this cannot be changed) and I want to find out when the batch file has finished
Any help would be appricated
Cheers
Chris
-
Jul 7th, 2000, 08:51 AM
#2
Member
A MacGyver tip
Create a temporary file when your batch file start.
Delete it when your batch file has finish.
In your VB code, look for the temporary file. If it's still there, you batch isn't finish. If it's not there, then your batch has finish.
I've just looking for an API to get the process name but i didn't find one.
-
Jul 7th, 2000, 08:59 AM
#3
I am not sure how you want to know when it finishes. Do you want to keep your program running, or wait for the batch file to finish before your program continues?
-
Jul 7th, 2000, 09:03 AM
#4
You can start the batchfile with CreateProcess. This returns a process handle. With this processHandle you can call WaitForSingleObject to check if the job is finished. When I get home I will look for a sample, the samples I have here (at work) are to mixed up in other code.
-
Jul 9th, 2000, 04:48 AM
#5
New Member
This will hold your application up while waiting for the batchfile to finish:
in a Module:
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
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
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
'*** Call this function with the batchfile as the filename argument
Public Sub ExecApp(FileName$)
Dim ProcInfo As PROCESS_INFORMATION
Dim StartInfo As STARTUPINFO
StartInfo.cb = Len(StartInfo)
'Start the specified application
ret& = CreateProcessA(0&, FileName$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, StartInfo, ProcInfo)
'Hold on for app to finish
ret& = WaitForSingleObject(ProcInfo.hProcess, INFINITE)
ret& = CloseHandle(ProcInfo.hProcess)
End Sub
In your form:
Private Sub Form_Load()
Call ExecApp("c:\thabatch.bat")
MsgBox "Finished!"
End Sub
have a nice day =)
/matse
-
Jul 9th, 2000, 10:27 AM
#6
_______
<?>
Code:
Option Explicit
Private Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
'Use this line in click event (substitute the URL for your own):
'call the bat file this way..it exposes the dos shell and
'then closes it when it is finished it's thing.
Private Sub Command1_Click()
Dim h As Long
h = Shell(Environ("COMSPEC") & " /C C:\yourfile.bat")
DoEvents
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|