cs_toinou78
Messages postés5Date d'inscriptionjeudi 1 septembre 2005StatutMembreDernière intervention19 octobre 2005
-
18 oct. 2005 à 17:43
cs_toinou78
Messages postés5Date d'inscriptionjeudi 1 septembre 2005StatutMembreDernière intervention19 octobre 2005
-
19 oct. 2005 à 16:50
Bonjour,
Je rencontre actuellement un problème dans mon appli car j'enchaine 3 Shell de suite et d'après ce que je lis dans MSDN, Shell est asynchrone par défaut. Je voudrais savoir comment je peux le mettre synchrone , c'est à dire attendre qu'il se termine avant de passer à la suite.
cs_pluplu
Messages postés615Date d'inscriptionmercredi 18 décembre 2002StatutMembreDernière intervention 4 juillet 2012 18 oct. 2005 à 21:18
' CreateProcess API
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 lRet&
' ****************************************************************************
' * Exécute un programme en mode synchrone (attend la fin) *
' ****************************************************************************
Public Function ShellAndWait(Cmd$, wShow&) As Long
'OK : 0 or Exitcode, Err : 111
Dim Proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ExitCode&, lr&, wo&
'Start the shelled application:
lRet& = CreateProcessA(0&, Cmd$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, Proc)
If lRet& = 0 Then
'Not executed .. or not found ...
ShellAndWait = 111
Exit Function
End If
'Wait for the shelled application to finish:
Do
wo& = WaitForSingleObject(Proc.hProcess, 0) 'Actif=258, Inactif=0
DoEvents
Loop Until wo& = 0
lRet& = GetExitCodeProcess(Proc.hProcess, ExitCode&)
If lRet& <> 1 Then ExitCode& = 0 'GetExitCodeProcess Error
lRet& = CloseHandle(Proc.hProcess)
ShellAndWait = ExitCode&
End Function
Met tout cela dans un modul et lance la command de ton shell par ShellAndWait et ça doit marcher
cs_toinou78
Messages postés5Date d'inscriptionjeudi 1 septembre 2005StatutMembreDernière intervention19 octobre 2005 19 oct. 2005 à 11:33
Bonjour,
Tout d'abord, merci pour vos réponses.
Comme je suis encore débutant en VB, je n'ai pas trop compris le Close Handle. Je suis également allé voir le lien fourni par Pascal sur developpez.net mais le code fait appel à une fonction LancerProcess qui n'est pas fournie. Je vais chercher le code d'origine pour le trouver.
Sinon, j'ai essayé la première solution fournie par Pascal mais j'ai une erreur car il ne trouve pas la fonction CreateProcessA...
Merci d'avance pour votre aide.
Vous n’avez pas trouvé la réponse que vous recherchez ?
cs_pluplu
Messages postés615Date d'inscriptionmercredi 18 décembre 2002StatutMembreDernière intervention 4 juillet 2012 19 oct. 2005 à 13:37
Sorry c'est parceque je l'ai recopié d'une grosse library voila ce qu'il faut rajouter dans la partie déclaration du modul
Private 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