Mickey
-
26 juil. 2000 à 10:59
cs_nanane
Messages postés6Date d'inscriptionjeudi 10 avril 2003StatutMembreDernière intervention29 mai 2009
-
7 mai 2003 à 10:26
Comment attendre la fin d'un executable externe lancé par SHELL
pour poursuivre le déroulement du programme VB ?
Merci
Derrick soft
Messages postés97Date d'inscriptionjeudi 10 mai 2001StatutMembreDernière intervention20 juin 2005 21 avril 2002 à 05:08
Bonsoir,
voici un code :
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
Public 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
Public Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
Public Sub ExcecuteEtAttend(ByVal RunProg As String)
Dim RetVal As Long
Dim proc As PROCESS_INFORMATION
Dim StartInf As STARTUPINFO
StartInf.cb = Len(StartInf)
RetVal = CreateProcessA(0&, RunProg, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc)
RetVal = WaitForSingleObject(proc.hProcess, INFINITE)
RetVal = CloseHandle(proc.hProcess)
End Sub
cs_nanane
Messages postés6Date d'inscriptionjeudi 10 avril 2003StatutMembreDernière intervention29 mai 2009 7 mai 2003 à 10:26
J'ai essayer ce code dans une macro Excel (pour lancer Notepad), et il m'est arrivé un truc bizaroide...
Je m'explique :
Pour faire "plus joli", j'ai mis chaque paramètre de la fonction CretaProcessA sur une ligne, style :
Public 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
Et bien dès que je sauvegardait mon fichier excel, il me créait un fichier "sauvegarde" avec un nom aléatoire (sur 8 caractères) contenant les mêmes données que mon ficher excel.
Et cela provient bien "a priori" de la mise en ligne des paramètres, car en remettant les paramètres comme avant, ça ne le faisait plus...