Bonjour,
J'ai lu cette discussion mais ça ne marche plus avec Access 2013 64 bits.
Rien ne se passe, la commande n'est pas exécutée
Pourquooooooooi ?
Bonjour,
J'ai lu cette discussion mais ça ne marche plus avec Access 2013 64 bits.
Rien ne se passe, la commande n'est pas exécutée
Pourquooooooooi ?
Bonjour,
normal car la déclaration d'API est différente en 64 bits !
A lire : Développer avec Office 64 bits …
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #If win64 Then Private Declare PtrSafe Function WaitForSingleObject Lib "kernel32" _ (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare PtrSafe Function CloseHandle Lib "kernel32" _ (ByVal hObject As Long) As Long Private Declare PtrSafe Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long #Else Private Declare Function WaitForSingleObject Lib "kernel32" _ (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function CloseHandle Lib "kernel32" _ (ByVal hObject As Long) As Long Private Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long #End If Private Const INFINITE = -1& Private Const SYNCHRONIZE = &H100000 Private Sub Command1_Click() Dim iTask As Long, ret As Long, pHandle As Long iTask = Shell("notepad.exe", vbNormalFocus) pHandle = OpenProcess(SYNCHRONIZE, False, iTask) ret = WaitForSingleObject(pHandle, INFINITE) ret = CloseHandle(pHandle) MsgBox "Process Finished! Thank you" End Sub
Bonjour et bonne année,
Une piste :
Hervé.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 Public Declare Function GetWindowText _ Lib "user32" _ Alias "GetWindowTextA" ( _ ByVal hWnd As Long, _ ByVal lpString As String, _ ByVal cch As Long) As Long Public Declare Function EnumWindows _ Lib "user32" ( _ ByVal lpEnumFunc As Long, _ ByVal lParam As Long) As Long Dim Ouvert As String Dim NomProg As String 'proc de test, à adapter : Sub Test() Dim lResult As Long NomProg = "Excel" 'cherche si Excel est ouvert lResult = EnumWindows(AddressOf ProgrammeOuvert, 0&) MsgBox Ouvert End Sub 'cherche dans le titre des fenêtres le nom du programme Public Function ProgrammeOuvert(ByVal hWnd As Long, _ ByVal lgParam As Long) As Long Dim Buffer As String Dim Result As Long Buffer = Space(255) Result = GetWindowText(hWnd, Buffer, 255) If Left(Buffer, 1) <> Chr(0) Then If InStr(UCase(Trim(Buffer)), UCase(NomProg)) <> 0 Then Ouvert = NomProg & " est ouvert !" Exit Function Else Ouvert = NomProg & " est fermé !" End If End If ProgrammeOuvert = 1 End Function
Effectivement, en 64bit l'appel aux API est différent.
Le code ci dessous fonctionne: lancement de l'appli + attente de fermeture.
Cerise sur le gâteau: un paramètre permet d'afficher ou de masquer la fenêtre (0 = show, 5 = hide). Indispensable pour exécuter une boucle de batchs en tache de fond, sans parasiter l'affichage et le focus.
Merci à tous !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 Private Const STARTF_USESHOWWINDOW& = &H1 Private Const NORMAL_PRIORITY_CLASS = &H20& Private Const INFINITE = -1& 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 Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal _ hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare PtrSafe 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 Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal _ hObject As Long) As Long Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long) Dim proc As PROCESS_INFORMATION Dim start As STARTUPINFO Dim ret As Long ' Initialize the STARTUPINFO structure: With start .cb = Len(start) If Not IsMissing(WindowStyle) Then .dwFlags = STARTF_USESHOWWINDOW .wShowWindow = WindowStyle End If End With ' Start the shelled application: ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _ NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc) ' Wait for the shelled application to finish: ret& = WaitForSingleObject(proc.hProcess, INFINITE) ret& = CloseHandle(proc.hProcess) End Sub
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager