[quote=150408:@Alain Bailleul]These are two functions (ShellWait and ShellDontWait) I use frequently (in my RB2007, so may need some changes for Xojo). Never know it helps somehow
Function ShellDontWait(sInCommandline as String, Visible as Boolean) As Boolean
#if targetWin32 then
Declare Function CreateProcessA Lib "kernel32" (lpApplicationName As integer, lpCommandLine As cString, lpProcessAttributes As integer, lpThreadAttributes As integer, bInheritHandles As integer, dwCreationFlags As integer, lpEnvironment As integer, lpCurrentDirectory As cstring, lpStartupInfo As ptr, lpProcessInformation As ptr) As integer
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const NORMAL_PRIORITY_CLASS = &H20
Dim Ret As integer
Dim StartInf As memoryblock
Dim Proc as MemoryBlock
Startinf = newmemoryBlock(76)
Startinf.long(44) = 1 /// set flags to use showwindow
If Visible then
Startinf.long(48) = SW_SHOWNORMAL
Else
Startinf.long(48) = SW_HIDE
End
Proc = newmemoryBlock(16)
StartInf.long(0) = StartInf.size
Ret = CreateProcessA(0,sInCommandline, 0, 0, 1,NORMAL_PRIORITY_CLASS, 0, "C:\", StartInf, Proc) //replace C:\\ with your desired working directory
Return True
#endif
End Function
[code]
Function ShellWait(sInCommandline as String, Visible as Boolean) As Boolean
#if targetWin32 then
Declare Function CreateProcessA Lib "kernel32" (lpApplicationName As integer, lpCommandLine As cString, lpProcessAttributes As integer, lpThreadAttributes As integer, bInheritHandles As integer, dwCreationFlags As integer, lpEnvironment As integer, lpCurrentDirectory As cstring, lpStartupInfo As ptr, lpProcessInformation As ptr) As integer
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (dwMilliseconds As integer)
Declare Function WaitForSingleObject Lib "kernel32" (hHandle As integer, dwMilliseconds As integer) As integer
Declare Function CloseHandle Lib "kernel32" (hObject As integer) As integer
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const WAIT_OBJECT_0 = 0
Const WAIT_TIMEOUT = &H102
Const NORMAL_PRIORITY_CLASS = &H20
Dim Ret As integer
Dim StartInf As memoryblock
Dim Proc as MemoryBlock
Startinf = newmemoryBlock(76)
Startinf.long(44) = 1 /// set flags to use showwindow
If Visible then
Startinf.long(48) = SW_SHOWNORMAL
Else
Startinf.long(48) = SW_HIDE
End
Proc = newmemoryBlock(16)
StartInf.long(0) = StartInf.size
Ret = CreateProcessA(0,sInCommandline, 0, 0, 1,NORMAL_PRIORITY_CLASS, 0, "C:\", StartInf, Proc) //replace C:\\ with your desired working directory
If Ret <> 0 then
Do
Ret = WaitForSingleObject(proc.long(0), 300) /// longer than 5000 will cause app to show as 'not responding' in the task list
if Ret = WAIT_OBJECT_0 then
/// Application has terminated
Ret = CloseHandle(proc.long(0))
return true
elseif Ret = WAIT_TIMEOUT then
/// keep waiting
else
Ret = CloseHandle(proc.long(0))
return false
end
app.DoEvents
Sleep(300)
Loop
Else
/// bad command line
return false
End
#endif
End Function
[/code][/quote]
I guess the code below will do the same.
Dim oWshShell As OleObject
Dim intRun As Integer
// oWshShell.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
// When bWaitOnReturn is True wait till notepad is closed
// When bWaitOnReturn is False continue the code and display msgbox
// More informations see: http://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.84%29.aspx
// Opens notepad and first Display Msgbox when notepad is closed
oWshShell = New Oleobject("WScript.Shell")
intRun = oWshShell.Run("notepad ", 1, true)
Msgbox("Return Value: "+str(intRun))
exception err as oleexception
msgbox err.message
oWshShell = Nil