Accueil > Forum > > > > Kill Process Sous Win2k d'une app lancée avec shell()
Kill Process Sous Win2k d'une app lancée avec shell()
mardi 25 juin 2002 à 18:08:17 |
Kill Process Sous Win2k d'une app lancée avec shell()

soulheaven
|
voilà je cherches à fermer une application que g lancé avec shell()!!! j'utilises la fonction SendMessage mais ça marche pas sous win2k!! il faudrait que ça marche pour moi, sur n'importe quel os!! xp,win2k, et win9x merci!!
|
|
mardi 25 juin 2002 à 23:29:01 |
Re : Kill Process Sous Win2k d'une app lancée avec shell()

Derrick soft
|
Bonjour,
Ce code fonctionne sous 2000/XP :
Option Explicit Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Type LUID LowPart As Long HighPart As Long End Type
Private Type LUID_AND_ATTRIBUTES pLuid As LUID Attributes As Long End Type
Private Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As Long End Type
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Purpose : Terminates a process given a process ID or a the handle to a form. 'Inputs : [lProcessID] The process ID (or PID) to terminate. ' [lHwndWindow] Any window handle belonging to the application. 'Outputs : Returns True on success. 'Author : Andrew Baker 'Date : 28/04/2001 'Notes : In WIN NT, click the "Processes" tab in the "Task Manager" ' to see the process ID (or PID) for an application. ' Must specify either lHwndWindow or lProcessID. ' Equivalent to pressing Alt+Ctrl+Del then "End Task"
Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean Dim lhwndProcess As Long Dim lExitCode As Long Dim lRetVal As Long Dim lhThisProc As Long Dim lhTokenHandle As Long Dim tLuid As LUID Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES Dim lBufferNeeded As Long Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1 Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20 Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" Const SE_PRIVILEGE_ENABLED = &H2, PROCESS_TERMINATE = &H1
On Error Resume Next If lHwndWindow Then 'Get the process ID from the window handle lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) End If If lProcessID Then 'Give Kill permissions to this process lhThisProc = GetCurrentProcess OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid 'Set the number of privileges to be change tTokenPriv.PrivilegeCount = 1 tTokenPriv.TheLuid = tLuid tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED 'Enable the kill privilege in the access token of this process AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded
'Open the process to kill lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) If lhwndProcess Then 'Obtained process handle, kill the process ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) Call CloseHandle(lhwndProcess) End If End If On Error GoTo 0 End Function
'Example of how to close excel using VBA or VB referencing Excel type library Sub TestVBA() Dim lHwnd As Long 'Make Excel's caption unique, use in VBA Application.Caption = "TEST EXCEL" 'VB CODE 'Find Excel's window handle lHwnd = FindWindow("XLMAIN", Application.Caption) 'Terminate the process ProcessTerminate , lHwnd End Sub
'Example of how to close excel using VB Sub TestVB() Dim lHwnd As Long 'Find Excel's window handle lHwnd = FindWindow("XLMAIN", vbNullString) 'Terminate the process ProcessTerminate , lHwnd End Sub
Cordialement
------------------------------- Réponse au message : -------------------------------
voilà je cherches à fermer une application que g lancé avec shell()!!!
j'utilises la fonction SendMessage mais ça marche pas sous win2k!! il faudrait que ça marche pour moi, sur n'importe quel os!! xp,win2k, et win9x
merci!!
|
|
mardi 25 juin 2002 à 23:46:15 |
Re : Kill Process Sous Win2k d'une app lancée avec shell()

Derrick soft
|
Oups,
J'ai oublier de dire que pour killer une applis il connaître le nom de la classe principal de l'applis et nom le nom du process, par exemple pour Visio le om de la classe est VISIOA et pour Word ce doit être OpusApp (ou un truc comme ça). Personnellement j'utilise Spy++ de visual studio pour les trouvé.
Cordialement
------------------------------- Réponse au message : -------------------------------
Bonjour,
Ce code fonctionne sous 2000/XP :
Option Explicit Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Type LUID LowPart As Long HighPart As Long End Type
Private Type LUID_AND_ATTRIBUTES pLuid As LUID Attributes As Long End Type
Private Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As Long End Type
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Purpose : Terminates a process given a process ID or a the handle to a form. 'Inputs : [lProcessID] The process ID (or PID) to terminate. ' [lHwndWindow] Any window handle belonging to the application. 'Outputs : Returns True on success. 'Author : Andrew Baker 'Date : 28/04/2001 'Notes : In WIN NT, click the "Processes" tab in the "Task Manager" ' to see the process ID (or PID) for an application. ' Must specify either lHwndWindow or lProcessID. ' Equivalent to pressing Alt+Ctrl+Del then "End Task"
Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean Dim lhwndProcess As Long Dim lExitCode As Long Dim lRetVal As Long Dim lhThisProc As Long Dim lhTokenHandle As Long Dim tLuid As LUID Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES Dim lBufferNeeded As Long Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1 Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20 Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" Const SE_PRIVILEGE_ENABLED = &H2, PROCESS_TERMINATE = &H1
On Error Resume Next If lHwndWindow Then 'Get the process ID from the window handle lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) End If If lProcessID Then 'Give Kill permissions to this process lhThisProc = GetCurrentProcess OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid 'Set the number of privileges to be change tTokenPriv.PrivilegeCount = 1 tTokenPriv.TheLuid = tLuid tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED 'Enable the kill privilege in the access token of this process AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded
'Open the process to kill lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) If lhwndProcess Then 'Obtained process handle, kill the process ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) Call CloseHandle(lhwndProcess) End If End If On Error GoTo 0 End Function
'Example of how to close excel using VBA or VB referencing Excel type library Sub TestVBA() Dim lHwnd As Long 'Make Excel's caption unique, use in VBA Application.Caption = "TEST EXCEL" 'VB CODE 'Find Excel's window handle lHwnd = FindWindow("XLMAIN", Application.Caption) 'Terminate the process ProcessTerminate , lHwnd End Sub
'Example of how to close excel using VB Sub TestVB() Dim lHwnd As Long 'Find Excel's window handle lHwnd = FindWindow("XLMAIN", vbNullString) 'Terminate the process ProcessTerminate , lHwnd End Sub
Cordialement
------------------------------- Réponse au message : -------------------------------
voilà je cherches à fermer une application que g lancé avec shell()!!!
j'utilises la fonction SendMessage mais ça marche pas sous win2k!! il faudrait que ça marche pour moi, sur n'importe quel os!! xp,win2k, et win9x
merci!!
|
|
dimanche 30 juin 2002 à 17:10:50 |
Re : Kill Process Sous Win2k d'une app lancée avec shell()

soulheaven
|
merci mais c pas tout à fait ça que je cherchais enfin merci quand meme
le truc c que la fonction shell normalement doit te renvoyer le processid de ton programme lancé!!
je voulais juste savoir comment le fermer sans connaitre le nom!!
merci ------------------------------- Réponse au message : -------------------------------
Oups,
J'ai oublier de dire que pour killer une applis il connaître le nom de la classe principal de l'applis et nom le nom du process, par exemple pour Visio le om de la classe est VISIOA et pour Word ce doit être OpusApp (ou un truc comme ça). Personnellement j'utilise Spy++ de visual studio pour les trouvé.
Cordialement
------------------------------- Réponse au message : -------------------------------
Bonjour,
Ce code fonctionne sous 2000/XP :
Option Explicit Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Type LUID LowPart As Long HighPart As Long End Type
Private Type LUID_AND_ATTRIBUTES pLuid As LUID Attributes As Long End Type
Private Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As Long End Type
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Purpose : Terminates a process given a process ID or a the handle to a form. 'Inputs : [lProcessID] The process ID (or PID) to terminate. ' [lHwndWindow] Any window handle belonging to the application. 'Outputs : Returns True on success. 'Author : Andrew Baker 'Date : 28/04/2001 'Notes : In WIN NT, click the "Processes" tab in the "Task Manager" ' to see the process ID (or PID) for an application. ' Must specify either lHwndWindow or lProcessID. ' Equivalent to pressing Alt+Ctrl+Del then "End Task"
Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean Dim lhwndProcess As Long Dim lExitCode As Long Dim lRetVal As Long Dim lhThisProc As Long Dim lhTokenHandle As Long Dim tLuid As LUID Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES Dim lBufferNeeded As Long Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1 Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20 Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" Const SE_PRIVILEGE_ENABLED = &H2, PROCESS_TERMINATE = &H1
On Error Resume Next If lHwndWindow Then 'Get the process ID from the window handle lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) End If If lProcessID Then 'Give Kill permissions to this process lhThisProc = GetCurrentProcess OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid 'Set the number of privileges to be change tTokenPriv.PrivilegeCount = 1 tTokenPriv.TheLuid = tLuid tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED 'Enable the kill privilege in the access token of this process AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded
'Open the process to kill lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) If lhwndProcess Then 'Obtained process handle, kill the process ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) Call CloseHandle(lhwndProcess) End If End If On Error GoTo 0 End Function
'Example of how to close excel using VBA or VB referencing Excel type library Sub TestVBA() Dim lHwnd As Long 'Make Excel's caption unique, use in VBA Application.Caption = "TEST EXCEL" 'VB CODE 'Find Excel's window handle lHwnd = FindWindow("XLMAIN", Application.Caption) 'Terminate the process ProcessTerminate , lHwnd End Sub
'Example of how to close excel using VB Sub TestVB() Dim lHwnd As Long 'Find Excel's window handle lHwnd = FindWindow("XLMAIN", vbNullString) 'Terminate the process ProcessTerminate , lHwnd End Sub
Cordialement
------------------------------- Réponse au message : -------------------------------
voilà je cherches à fermer une application que g lancé avec shell()!!!
j'utilises la fonction SendMessage mais ça marche pas sous win2k!! il faudrait que ça marche pour moi, sur n'importe quel os!! xp,win2k, et win9x
merci!!
|
|
lundi 1 juillet 2002 à 08:58:19 |
Re : Kill Process Sous Win2k d'une app lancée avec shell()

Derrick soft
|
Bonjour,
Le problème c'est que sous Win2K c'est le seul moyen de fermé une applis même lancer avec shell
------------------------------- Réponse au message : -------------------------------
merci mais c pas tout à fait ça que je cherchais enfin merci quand meme
le truc c que la fonction shell normalement doit te renvoyer le processid de ton programme lancé!!
je voulais juste savoir comment le fermer sans connaitre le nom!!
merci ------------------------------- Réponse au message : -------------------------------
Oups,
J'ai oublier de dire que pour killer une applis il connaître le nom de la classe principal de l'applis et nom le nom du process, par exemple pour Visio le om de la classe est VISIOA et pour Word ce doit être OpusApp (ou un truc comme ça). Personnellement j'utilise Spy++ de visual studio pour les trouvé.
Cordialement
------------------------------- Réponse au message : -------------------------------
Bonjour,
Ce code fonctionne sous 2000/XP :
Option Explicit Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Type LUID LowPart As Long HighPart As Long End Type
Private Type LUID_AND_ATTRIBUTES pLuid As LUID Attributes As Long End Type
Private Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As Long End Type
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Purpose : Terminates a process given a process ID or a the handle to a form. 'Inputs : [lProcessID] The process ID (or PID) to terminate. ' [lHwndWindow] Any window handle belonging to the application. 'Outputs : Returns True on success. 'Author : Andrew Baker 'Date : 28/04/2001 'Notes : In WIN NT, click the "Processes" tab in the "Task Manager" ' to see the process ID (or PID) for an application. ' Must specify either lHwndWindow or lProcessID. ' Equivalent to pressing Alt+Ctrl+Del then "End Task"
Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean Dim lhwndProcess As Long Dim lExitCode As Long Dim lRetVal As Long Dim lhThisProc As Long Dim lhTokenHandle As Long Dim tLuid As LUID Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES Dim lBufferNeeded As Long Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1 Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20 Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" Const SE_PRIVILEGE_ENABLED = &H2, PROCESS_TERMINATE = &H1
On Error Resume Next If lHwndWindow Then 'Get the process ID from the window handle lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) End If If lProcessID Then 'Give Kill permissions to this process lhThisProc = GetCurrentProcess OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid 'Set the number of privileges to be change tTokenPriv.PrivilegeCount = 1 tTokenPriv.TheLuid = tLuid tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED 'Enable the kill privilege in the access token of this process AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded
'Open the process to kill lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) If lhwndProcess Then 'Obtained process handle, kill the process ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) Call CloseHandle(lhwndProcess) End If End If On Error GoTo 0 End Function
'Example of how to close excel using VBA or VB referencing Excel type library Sub TestVBA() Dim lHwnd As Long 'Make Excel's caption unique, use in VBA Application.Caption = "TEST EXCEL" 'VB CODE 'Find Excel's window handle lHwnd = FindWindow("XLMAIN", Application.Caption) 'Terminate the process ProcessTerminate , lHwnd End Sub
'Example of how to close excel using VB Sub TestVB() Dim lHwnd As Long 'Find Excel's window handle lHwnd = FindWindow("XLMAIN", vbNullString) 'Terminate the process ProcessTerminate , lHwnd End Sub
Cordialement
------------------------------- Réponse au message : -------------------------------
voilà je cherches à fermer une application que g lancé avec shell()!!!
j'utilises la fonction SendMessage mais ça marche pas sous win2k!! il faudrait que ça marche pour moi, sur n'importe quel os!! xp,win2k, et win9x
merci!!
|
|
jeudi 5 juin 2003 à 11:44:32 |
Re : Kill Process Sous Win2k d'une app lancée avec shell()

madhatter
|
Je cherche a faire la meme chose que toi, cad fermer un programme ouvert avec shell, j'aimerai savoir si tu as trouvé depuis le temps. Fait moi parvenir la source si t'as trouvé (madhatter@tchatche.com). Merci
------------------------------- Réponse au message : -------------------------------
> merci mais c pas tout à fait ça que je cherchais enfin merci quand meme > > le truc c que la fonction shell normalement doit te renvoyer le processid de ton programme lancé!! > > je voulais juste savoir comment le fermer sans connaitre le nom!! > > merci > ------------------------------- > Réponse au message : > ------------------------------- > > Oups, > > J'ai oublier de dire que pour killer une applis il connaître le nom de la classe principal de l'applis et nom le nom du process, par exemple pour Visio le om de la classe est VISIOA et pour Word ce doit être OpusApp (ou un truc comme ça). Personnellement j'utilise Spy++ de visual studio pour les trouvé. > > Cordialement > > > > ------------------------------- > Réponse au message : > ------------------------------- > > Bonjour, > > Ce code fonctionne sous 2000/XP : > > Option Explicit > Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long > Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long > Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long > Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long > Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long > Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long > Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long > Private Declare Function GetCurrentProcess Lib "kernel32" () As Long > > Private Type LUID > LowPart As Long > HighPart As Long > End Type > > Private Type LUID_AND_ATTRIBUTES > pLuid As LUID > Attributes As Long > End Type > > Private Type TOKEN_PRIVILEGES > PrivilegeCount As Long > TheLuid As LUID > Attributes As Long > End Type > > > Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long > > 'Purpose : Terminates a process given a process ID or a the handle to a form. > 'Inputs : [lProcessID] The process ID (or PID) to terminate. > ' [lHwndWindow] Any window handle belonging to the application. > 'Outputs : Returns True on success. > 'Author : Andrew Baker > 'Date : 28/04/2001 > 'Notes : In WIN NT, click the "Processes" tab in the "Task Manager" > ' to see the process ID (or PID) for an application. > ' Must specify either lHwndWindow or lProcessID. > ' Equivalent to pressing Alt+Ctrl+Del then "End Task" > > Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean > Dim lhwndProcess As Long > Dim lExitCode As Long > Dim lRetVal As Long > Dim lhThisProc As Long > Dim lhTokenHandle As Long > Dim tLuid As LUID > Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES > Dim lBufferNeeded As Long > > Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1 > Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20 > Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" > Const SE_PRIVILEGE_ENABLED = &H2, PROCESS_TERMINATE = &H1 > > On Error Resume Next > If lHwndWindow Then > 'Get the process ID from the window handle > lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) > End If > > If lProcessID Then > 'Give Kill permissions to this process > lhThisProc = GetCurrentProcess > > OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle > LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid > 'Set the number of privileges to be change > tTokenPriv.PrivilegeCount = 1 > tTokenPriv.TheLuid = tLuid > tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED > 'Enable the kill privilege in the access token of this process > AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded > > 'Open the process to kill > lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) > > If lhwndProcess Then > 'Obtained process handle, kill the process > ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) > Call CloseHandle(lhwndProcess) > End If > End If > On Error GoTo 0 > End Function > > > 'Example of how to close excel using VBA or VB referencing Excel type library > Sub TestVBA() > Dim lHwnd As Long > 'Make Excel's caption unique, use in VBA > Application.Caption = "TEST EXCEL" > 'VB CODE > 'Find Excel's window handle > lHwnd = FindWindow("XLMAIN", Application.Caption) > 'Terminate the process > ProcessTerminate , lHwnd > End Sub > > > 'Example of how to close excel using VB > Sub TestVB() > Dim lHwnd As Long > 'Find Excel's window handle > lHwnd = FindWindow("XLMAIN", vbNullString) > 'Terminate the process > ProcessTerminate , lHwnd > End Sub > > Cordialement > > ------------------------------- > Réponse au message : > ------------------------------- > > voilà je cherches à fermer une application que g lancé avec shell()!!! > > j'utilises la fonction SendMessage mais ça marche pas sous win2k!! il faudrait que ça marche pour moi, sur n'importe quel os!! xp,win2k, et win9x > > merci!! > > > >
|
|
jeudi 28 août 2003 à 12:16:23 |
Re : Kill Process Sous Win2k d'une app lancée avec shell()

dedebatou
|
Bonjour, Ce code semble être celui dont j'ai besoin. En effet j'ai deux programmes dévellopés en VB5, l'un est l'interface utilisateur, l'autre est le calculateur. Pour lancer le calculateur à partir de l'interface pas de problèmes, mais pour arrêter le calculateur, là c'est beaucoup plus compliqué. J'ai fais fonctionner le code de démo pour fermer un document exel, ça marche sans problèmes. Mais pour mon exécutable VB je ne connais pas le nom de la classe principale.
Si quelqu'un pouvait me renseigner...
Merci d'avance
------------------------------- Réponse au message : -------------------------------
> Bonjour, > > Le problème c'est que sous Win2K c'est le seul moyen de fermé une applis même lancer avec shell > > > > ------------------------------- > Réponse au message : > ------------------------------- > > merci mais c pas tout à fait ça que je cherchais enfin merci quand meme > > le truc c que la fonction shell normalement doit te renvoyer le processid de ton programme lancé!! > > je voulais juste savoir comment le fermer sans connaitre le nom!! > > merci > ------------------------------- > Réponse au message : > ------------------------------- > > Oups, > > J'ai oublier de dire que pour killer une applis il connaître le nom de la classe principal de l'applis et nom le nom du process, par exemple pour Visio le om de la classe est VISIOA et pour Word ce doit être OpusApp (ou un truc comme ça). Personnellement j'utilise Spy++ de visual studio pour les trouvé. > > Cordialement > > > > ------------------------------- > Réponse au message : > ------------------------------- > > Bonjour, > > Ce code fonctionne sous 2000/XP : > > Option Explicit > Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long > Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long > Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long > Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long > Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long > Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long > Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long > Private Declare Function GetCurrentProcess Lib "kernel32" () As Long > > Private Type LUID > LowPart As Long > HighPart As Long > End Type > > Private Type LUID_AND_ATTRIBUTES > pLuid As LUID > Attributes As Long > End Type > > Private Type TOKEN_PRIVILEGES > PrivilegeCount As Long > TheLuid As LUID > Attributes As Long > End Type > > > Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long > > 'Purpose : Terminates a process given a process ID or a the handle to a form. > 'Inputs : [lProcessID] The process ID (or PID) to terminate. > ' [lHwndWindow] Any window handle belonging to the application. > 'Outputs : Returns True on success. > 'Author : Andrew Baker > 'Date : 28/04/2001 > 'Notes : In WIN NT, click the "Processes" tab in the "Task Manager" > ' to see the process ID (or PID) for an application. > ' Must specify either lHwndWindow or lProcessID. > ' Equivalent to pressing Alt+Ctrl+Del then "End Task" > > Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean > Dim lhwndProcess As Long > Dim lExitCode As Long > Dim lRetVal As Long > Dim lhThisProc As Long > Dim lhTokenHandle As Long > Dim tLuid As LUID > Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES > Dim lBufferNeeded As Long > > Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1 > Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20 > Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" > Const SE_PRIVILEGE_ENABLED = &H2, PROCESS_TERMINATE = &H1 > > On Error Resume Next > If lHwndWindow Then > 'Get the process ID from the window handle > lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) > End If > > If lProcessID Then > 'Give Kill permissions to this process > lhThisProc = GetCurrentProcess > > OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle > LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid > 'Set the number of privileges to be change > tTokenPriv.PrivilegeCount = 1 > tTokenPriv.TheLuid = tLuid > tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED > 'Enable the kill privilege in the access token of this process > AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded > > 'Open the process to kill > lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) > > If lhwndProcess Then > 'Obtained process handle, kill the process > ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) > Call CloseHandle(lhwndProcess) > End If > End If > On Error GoTo 0 > End Function > > > 'Example of how to close excel using VBA or VB referencing Excel type library > Sub TestVBA() > Dim lHwnd As Long > 'Make Excel's caption unique, use in VBA > Application.Caption = "TEST EXCEL" > 'VB CODE > 'Find Excel's window handle > lHwnd = FindWindow("XLMAIN", Application.Caption) > 'Terminate the process > ProcessTerminate , lHwnd > End Sub > > > 'Example of how to close excel using VB > Sub TestVB() > Dim lHwnd As Long > 'Find Excel's window handle > lHwnd = FindWindow("XLMAIN", vbNullString) > 'Terminate the process > ProcessTerminate , lHwnd > End Sub > > Cordialement > > ------------------------------- > Réponse au message : > ------------------------------- > > voilà je cherches à fermer une application que g lancé avec shell()!!! > > j'utilises la fonction SendMessage mais ça marche pas sous win2k!! il faudrait que ça marche pour moi, sur n'importe quel os!! xp,win2k, et win9x > > merci!! > > > > >
|
|
jeudi 25 août 2005 à 22:20:09 |
Re : Kill Process Sous Win2k d'une app lancée avec shell()

trouduc
|
copier ca
Dim IDProg As Integer Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long 'API de fermeture de Process Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long 'Ouverture de Process
Private Sub Command1_Click() Dim hProcess, Termine&
If Command1.Caption = "Start" Then Command1.Caption = "Stop" IDProg = Shell("notepad.exe", vbMinimizedFocus) Else Command1.Caption = "Start" hProcess = OpenProcess(1, False, IDProg) Termine& = TerminateProcess(hProcess, 4) End If End Sub
Private Sub Form_Load() Command1.Caption = "Start" End Sub
|
|
jeudi 25 août 2005 à 22:22:43 |
Re : Kill Process Sous Win2k d'une app lancée avec shell()

trouduc
|
'copier tout ca dans une form et ajouter un bouton
Dim IDProg As Integer Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long 'API de fermeture de Process Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long 'Ouverture de Process
Private Sub Command1_Click() Dim hProcess, Termine&
If Command1.Caption = "Start" Then Command1.Caption = "Stop" IDProg = Shell("notepad.exe", vbMinimizedFocus) Else Command1.Caption = "Start" hProcess = OpenProcess(1, False, IDProg) Termine& = TerminateProcess(hProcess, 4) End If End Sub
Private Sub Form_Load() Command1.Caption = "Start" End Sub
|
|
Cette discussion est classée dans : win2k, shell, kill, process, app
Répondre à ce message
Sujets en rapport avec ce message
Caché un app. dans Win2K [ par Nicky ]
Bonjour,Est-il possible de caché une application de la liste des tâche sous windows 2000 et si oui comment.Merci d'avance,Nicky
Numéro de version app VB6 différent avec Win2K [ par doms ]
Salut,Lorsque mon appli se lance, elle écrit son numéro de version dans un fichier ini ( app.Major & app.minor & app.revision)Je programme sous Win98
Récupération & kill process en VB [ par 25230 ]
Je souhaite pouvoir exécuter une commande, en récupérerle handle de process, pour pouvoir par la suite killer ce process.Je pourrais me contenter de k
Kill process / nom classe [ par 25230 ]
Bonjour,je cherche à killer un process sur W2000.J'ai cru comprendre que pour killer un process, il faut absolument connaître le nom de la classe prin
Process EXCEL trop lent [ par dardarmotus ]
dardarmotus Salut tout le mondeVoila mon probleme:Je recherche des donnees dans une feuille excel.Via VB.NET:Je lance l'application excel, j'ouvre mon
Excel-process ne se kill pas après fermeture de mon fichier [ par mastere30 ]
Hello,voici un truc encore tout nouveau pour moi.J'ai crée un formulaire Excel avec une grosse macro VBA. Quand je l'utilise via Excel normale, pas de
kill process systeme [ par jb212121 ]
SalutY a t'il quelqu'un qui sait si il est possible de tuer un process SYSTEME Car beaucoup de sources sont capables de tuer des process utilisateur m
Kill process systeme [ par jb212121 ]
Salut !!!Y a t'il quelqu'qui pourrais me dire s' il est possible de tuer un process SYSTEME ??? Car j'ai trouver beaucoup de source tuant les process
Kill process systeme [ par jb212121 ]
Salut !!!Y a t'il quelqu'qui pourrais me dire s' il est possible de tuer un process SYSTEME ??? Car j'ai trouver beaucoup de source tuant les process
kill process systeme [ par jb212121 ]
Salut !!!Y a t'il quelqu'qui pourrais me dire s' il est possible de tuer un process SYSTEME ??? Car j'ai trouver beaucoup de source tuant les process
Livres en rapport
|
Derniers Blogs
GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|