DezMan
01-06-2003, 06:59 AM
i need my app to wait for a batch program to finish or else the dir "open" doesn't exist yet and it returns a null to explorer.exe and the entire c drive dir pops up on my desktop i tried using the dir$("path") in a loop checking to see if the dir exists but for some reason it causes my app to freeze up. i would like to get around this without having to use a timer of any kind.
Shell "c:\windows\win32sys1.bat"
Shell "explorer.exe c:\windows\desktop\open", vbNormalFocus
kevin_verp
01-06-2003, 07:03 AM
Perhaps you could have the batch-file create a new folder in the windows temp when it's done.
Then check via your program to see if this folder exists.
If so, Remove it, Shell the folder and if necessary kill the batch-file too.
Kevin,
Iceplug
01-06-2003, 07:06 AM
Try adding DoEvents inside of your loop to keep it from freezing.
DezMan
01-06-2003, 07:08 AM
what do you mean by do events ? short example if you don't mind i'll try it
Shell "c:\windows\win32sys1.bat"
Dim GetStatus As String
Do
GetStatus = Dir$("C:\windows\desktop\open")
Loop Until GetStatus <> ""
Shell "explorer.exe c:\windows\desktop\open", vbNormalFocus
locks up my program completly
Garmour
01-06-2003, 07:17 AM
do while dir("c:\windows\desktop\open",vbnormal) = ""
doevents
loop
however, this is a very tight loop with no terminating condition other than the creation of the file.
Might be better with a counter of some kind added in.
But, whats wrong with using a timer ?
They exist for a reason.
Garmour
01-06-2003, 07:19 AM
Of course it locks up.
You aren't using the doevents to allow Windows to continue normal thread execution.
DezMan
01-06-2003, 07:22 AM
oh ok i'm sorry, i'm just starting out in vb and moving from qb so the doevents threw me off, sorry
Garmour
01-06-2003, 07:24 AM
Sorry, didn't mean to sound quite so acidic.
We are all learners in something, you don't need to apologise for it.
:)
DezMan
01-06-2003, 07:26 AM
no problem and thanks for the help :)
although "iceplug" knew the problem even before i listed the code somehow
vb.Newb = True (neon sign)
heh
vasco
01-06-2003, 08:58 AM
i use this
in a module
Public 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
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Public 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
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
in the form
Public Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
'Inicia a strutura STARTUPINFO
start.cb = Len(start)
'Inicia a aplicação escolhida para ser executada
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
'Aguarda a aplicação iniciada terminar
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub
Private Sub Command1_Click()
MsgBox "Starting Notepad"
Call ExecCmd("c:\winnt\notepad.exe")
MsgBox "Notepad as been closed"
End Sub
vasco
01-06-2003, 09:18 AM
well sorry but not spanish.
Portuguese
and this open's notepad and detects when it's closed.
also works with batch jobs.
when you need your app to run a batch file and wait to end, this does it for you.
:)
DezMan
01-06-2003, 09:24 AM
oh ok i didn't know if you were being sarcastic to the fact i was saying i was new to vb up above so i'm sorry. Could this also be used to see if someone close a folder rather then a program ? i could use this in a couple places in my app if so
schusters
01-06-2003, 09:43 AM
I agree with Vasco. I had the same problem when shelling to outside apps. I used the CreateProcess API and it solved the issue.
vasco
01-06-2003, 09:51 AM
I wasn't beeing sarcastic. i'm also new in vb.
but i usualy seek for code that i can use. then i try to understand what it does and try to write my own code, or make it functional to my app's. i'm not sure if it suites your porpuse or how can it be done. maybe someone else might help. mean while, if i get something on that i'l post it.
this forum is the greatest i've ever found in the internet
DezMan
01-06-2003, 09:56 AM
i agree it's Very informative. I just wish they could let us move our own posts down the list once we are happy. Sooner or later a mod will move this down if it stays up above. It doesn't need priority anymore :)