begin process at 2012 02 15 01:16:28
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Archive Visual Basic & VB.NET

 > 

Archives Visual Basic

 > 

Shell

 > 

Kill Process Sous Win2k d'une app lancée avec shell()


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

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


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 9,937 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales