Problème de Windows?

choupiz Messages postés 1 Date d'inscription mardi 21 juin 2005 Statut Membre Dernière intervention 22 juin 2005 - 22 juin 2005 à 08:22
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 22 juin 2005 à 11:43
Bonjour. J'ai un programme qui est sensé appeler une application et attendre que cette application se termine avant de continuer a tourner. Ca fonctionne tres bien sous NT et 2000 mais ça marche pas quand je veux le mettre sous XP. Voilà le bout de programme concerné si queulqu'un a une idée...
Le code a été récupéré sur ce site.

Merci d'avance

Public Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long


Public Function ExecCmd(cmdline$)
Dim reponse As Integer
Dim reponse2 As Long

reponse = Shell(cmdline$, vbHide)
Debug.Print reponse


If reponse > 0 Then
' Boucle d'attente de la fin d'exécution
Do
reponse2 = OpenProcess(PROCESS_QUERY_INFORMATION, False, reponse)
Debug.Print reponse2
Loop While (reponse2 <> 0)
End If
End Function

2 réponses

j621473 Messages postés 14 Date d'inscription mercredi 9 mars 2005 Statut Membre Dernière intervention 26 juillet 2007
22 juin 2005 à 08:42
Hello

Je suis novice en la matière mais j'utilise ShellWait et ca marche plutot bien

voici :

'Fonction privé qui fonctionne uniquement sur cette feuille


Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Private Const STILL_ACTIVE = &H103
Private Const PROCESS_QUERY_INFORMATION = &H400


' Fonction public qui éxécute JobToDo


Public Sub ShellWait(ByVal JobToDo As String)
Dim hProcess As Long, retval As Long

hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, vbMinimizedNoFocus))
Do
GetExitCodeProcess hProcess, retval
DoEvents
Sleep 100
Loop While retval = STILL_ACTIVE
End Sub

Private Sub Form_Load()
ShellWait "regedit /s " & GetShortPath("C:\Program Files") & "\XELEC\PCI\xelec_var.reg"
End Sub

voici voilou

A++
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
22 juin 2005 à 11:43
Y a pas besoin de boucle.

CreateProcess ou ShellExecuteEx
WaitForSingleObject
CloseHandle

ciao...
BruNews, MVP VC++
0
Rejoignez-nous