Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SHELL (Dos Batch)

Status
Not open for further replies.

sflau

Programmer
Oct 18, 2001
87
0
0
HK
I am using VB 6, want to execute a dos batch file, then, I use:

Shell "UPLOAD.BAT"

But I find that it will only call the batch file, without finish it, it will return to the program immediately, how can the program know whether this command is finished or not?
 
Many similar question threads already exist on this subject, one or more of them will tell you this.

Dim oShell As Object
Dim nRet As Long

Set oShell = CreateObject("WSCript.shell")
nRet = oShell.Run("upload.bat", , TRUE)
Set oShell = Nothing

TRUE says wait for completion, FALSE will produce your current situation.
 
Finally, I use API as the following code:

Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Public Declare Function OpenProcess Lib "kernel32" (ByVal fdwAccess As Long, ByVal fInherit As Boolean, ByVal IDProcess As Long) As Long

strShellCommand = App.Path & "\TEST.BAT"
lngExecOK = Shell(strShellCommand)
lProcessHandle = OpenProcess(&H100000, True, lngExecOK)
lReturnValue = WaitForSingleObject(lProcessHandle, 60000 * 60)

Thank you.
 
Just to be tidy maybe you should also close the handle afterwards - CloseHandle lProcessHandle.

Anyway glad it works for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top