Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3892 connectés 

 


Dernière réponse
Sujet : [VB] fonctions de kernel32.dll
trictrac Je me suis super inspire du code que tu m'as donne, et voila ce que ca donne, pour le lancement de acrobat reader 5.0.. il le lance, mais refuse de le tuer.
PS: non, c'est po si urgent, mais disons que pour l'instant je suis en stage, et que j'ai plus que ca pour finir mon petit prog... alors je ne peux pas ne plus rien faire d'ici ce soir

Code :
  1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
  2. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  3. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
  4. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
  5. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  6. Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
  7. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  8. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
  9. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
  10. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  11. Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
  12. Const GW_HWNDNEXT = 2
  13. Dim mWnd As Long
  14. Private CurrentPath$
  15. Function InstanceToWnd(ByVal target_pid As Long) As Long
  16.     Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
  17.     'Find the first window
  18.     test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
  19.     Do While test_hwnd <> 0
  20.         'Check if the window isn't a child
  21.         If GetParent(test_hwnd) = 0 Then
  22.             'Get the window's thread
  23.             test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
  24.             If test_pid = target_pid Then
  25.                 InstanceToWnd = test_hwnd
  26.                 Exit Do
  27.             End If
  28.         End If
  29.         'retrieve the next window
  30.         test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
  31.     Loop
  32. End Function
  33. Private Sub Form_Load()
  34. Dim Pid
  35. On Error GoTo ErrHanlder
  36. Pid = Shell("C:\Programs\Adobe\Acrobat 5.0\Reader\AcroRd32.exe", 1)
  37. DestroyWindow mWnd
  38. ErrHanlder:
  39.     If Err.Number = 76 Then
  40.         MsgBox "Acrobat Reader 5.0 doit etre à cet endroit: C:\Programs\Adobe\Acrobat 5.0\Reader\AcroRd32.exe"
  41.     End If
  42. End
  43. End Sub


Votre réponse
Nom d'utilisateur    Pour poster, vous devez être inscrit sur ce forum .... si ce n'est pas le cas, cliquez ici !
Le ton de votre message                        
                       
Votre réponse


[b][i][u][strike][spoiler][fixed][cpp][url][email][img][*]   
 
   [quote]
 

Options

 
Vous avez perdu votre mot de passe ?


Vue Rapide de la discussion
trictrac Je me suis super inspire du code que tu m'as donne, et voila ce que ca donne, pour le lancement de acrobat reader 5.0.. il le lance, mais refuse de le tuer.
PS: non, c'est po si urgent, mais disons que pour l'instant je suis en stage, et que j'ai plus que ca pour finir mon petit prog... alors je ne peux pas ne plus rien faire d'ici ce soir

Code :
  1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
  2. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  3. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
  4. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
  5. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  6. Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
  7. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  8. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
  9. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
  10. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  11. Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
  12. Const GW_HWNDNEXT = 2
  13. Dim mWnd As Long
  14. Private CurrentPath$
  15. Function InstanceToWnd(ByVal target_pid As Long) As Long
  16.     Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
  17.     'Find the first window
  18.     test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
  19.     Do While test_hwnd <> 0
  20.         'Check if the window isn't a child
  21.         If GetParent(test_hwnd) = 0 Then
  22.             'Get the window's thread
  23.             test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
  24.             If test_pid = target_pid Then
  25.                 InstanceToWnd = test_hwnd
  26.                 Exit Do
  27.             End If
  28.         End If
  29.         'retrieve the next window
  30.         test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
  31.     Loop
  32. End Function
  33. Private Sub Form_Load()
  34. Dim Pid
  35. On Error GoTo ErrHanlder
  36. Pid = Shell("C:\Programs\Adobe\Acrobat 5.0\Reader\AcroRd32.exe", 1)
  37. DestroyWindow mWnd
  38. ErrHanlder:
  39.     If Err.Number = 76 Then
  40.         MsgBox "Acrobat Reader 5.0 doit etre à cet endroit: C:\Programs\Adobe\Acrobat 5.0\Reader\AcroRd32.exe"
  41.     End If
  42. End
  43. End Sub

Bendes Si tu veux je teste ça ce soir chez moi et j'te dis quoi demain, ou c'est trop urgent ???
trictrac ca doit etre pour ca... je viens de lire que sous NT,  
Windows NT: The handle must have PROCESS_TERMINATE access. For more information, see Process Objects.
 
Si j'ai lance le programme, il me semble normal d'avoir le droit de le tuer, non?
Bendes Au boulot, win98 SE
 
Chez moi, win2K
 
Code tester au boulot

 

[edit]--Message édité par Bendes--[/edit]

trictrac Bendes> tu code sous kel OS??
JPA Tu peux trouver plein d'informations sur les DLLs avec le programme Scanbin écrit par J.C. Bellamy
voir : http://jc.bellamy.free.fr
A+
trictrac ben oui, avec la commande shell
 
PS: si tu ouvre kernell32 avec notepad, tu trouve une fonction ntterminateprocess, mais lorsque je la declare, il me dit quelle nexiste po
darkoli

trictrac a écrit a écrit :

ca marche tjs po...... c'est comme ca que j'avais fais, mais il ne veut pas tuer acrobat reader
PS: je suis sous NT, ca change qqch?




 
y'a peut etre un probleme de droit ?
est ce que c'est ton application qui a ouvert acrobat reader ?

trictrac ca marche tjs po...... c'est comme ca que j'avais fais, mais il ne veut pas tuer acrobat reader
PS: je suis sous NT, ca change qqch?
JPA tu as également des renseignements sur les API windows à  
http://www.allapi.net/agnet/index.php
A+
darkoli desole mais je ne connais pas vb.
 
pour savoir que ca fait parti de kernel32 ben tu vas voir la ou je te l'ai indiqué avec le lien. C'est la liste alphabetique des fonction de l'api win32 , puis tu cliques sur la lettre T et ensuite sur la fonction terminateProcess et ensuite tu vas a la fin du document et tu trouveras ton bonheur...
Bendes V'là un bel exemple, j'te laisse t'amuser avec :
 

Code :
  1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
  2. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  3. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
  4. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
  5. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  6. Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
  7. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  8. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
  9. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
  10. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  11. Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
  12. Const GW_HWNDNEXT = 2
  13. Dim mWnd As Long
  14. Function InstanceToWnd(ByVal target_pid As Long) As Long
  15.     Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
  16.     'Find the first window
  17.     test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
  18.     Do While test_hwnd <> 0
  19.         'Check if the window isn't a child
  20.         If GetParent(test_hwnd) = 0 Then
  21.             'Get the window's thread
  22.             test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
  23.             If test_pid = target_pid Then
  24.                 InstanceToWnd = test_hwnd
  25.                 Exit Do
  26.             End If
  27.         End If
  28.         'retrieve the next window
  29.         test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
  30.     Loop
  31. End Function
  32. Private Sub Form_Load()
  33.     'KPD-Team 1999
  34.     'URL: http://www.allapi.net/
  35.     'E-Mail: KPDTeam@Allapi.net
  36.     Dim Pid As Long
  37.     'Lock the window update
  38.     LockWindowUpdate GetDesktopWindow
  39.     'Execute notepad.Exe
  40.     Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)
  41.     If Pid = 0 Then MsgBox "Error starting the app"
  42.     'retrieve the handle of the window
  43.     mWnd = InstanceToWnd(Pid)
  44.     'Set the notepad's parent
  45.     SetParent mWnd, Me.hwnd
  46.     'Put the focus on notepad
  47.     Putfocus mWnd
  48.     'Unlock windowupdate
  49.     LockWindowUpdate False
  50. End Sub
  51. Private Sub Form_Unload(Cancel As Integer)
  52.     'Unload notepad
  53.     DestroyWindow mWnd
  54.     'End this program
  55.     TerminateProcess GetCurrentProcess, 0
  56. End Sub

trictrac desole d'abuser, mais ca, je l'avais trouver, et j'aurais voulu savoir comment kon fais pour l'exploiter dans VB... car je suis pas pro de la prog system....
PS: comment on fais pour savoir que ca concerne kernell32.dll
PPS: je viens d'essayer en declarant la fonction dans un module, il l'execute, ne cree pas d'erreur, mais ne termine pas le processus non plus

 

[edit]--Message édité par trictrac--[/edit]

darkoli ben c'est http://msdn.microsoft.com/library/ [...] c_3bjm.htm par exemple (ca fait au moins 10000 fois que je poste l'adresse, la logiquement tu devrais trouver ton bonheur et meme plus ...
 

Code :
  1. BOOL TerminateProcess(
  2.   HANDLE hProcess, // handle to the process
  3.   UINT uExitCode   // exit code for the process
  4. );

trictrac Comment kon fait pour connaiitre le prototype des fonctions incluses dans le kernell32.dll, et comment faire pour les inclure dans le code de VB, car il contient une fonction appele terminateProcess qui m'interresse, mais sans prototype, je ne peux rien en faire...
Est-ce qqun connait un site ou autre ou trouver le prototype des fonction incluses dans des DLL??

Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)