Accueil > > > PLEIN D'OPÉRATIONS SIMPLE POUR GÉRER LES PROCESS
PLEIN D'OPÉRATIONS SIMPLE POUR GÉRER LES PROCESS
Information sur la source
Description
voici ce que sa permet de faire: voire si une certaine app est ouverte retourner le hwnd d'un programme changer le titre d'une fenetre obtenir la liste des process killer des process (+ sécurité pour explorer) retourner le titre d'un handle (mettez sa dans un module)
Source
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
- Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
- Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
- Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
- Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
- Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
- Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
- Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
- Const Fermer = &H10
- Const GW_HWNDFIRST = 0
- Const GW_HWNDNEXT = 2
- Public Function GetHandle(Titre As String) As Long
- GetHandle = FindWindow(vbNullString, Titre)
- End Function
-
- Public Sub SetTitle(hwnd As Long, texte As String)
- SetWindowText hwnd, texte
- End Sub
- Public Function IsAppRunning(Titre As String) As Boolean
- Dim handle
- handle = FindWindow(vbNullString, Titre)
- If handle = 0 Then IsAppRunning = False Else: IsAppRunning = True
- End Function
- Public Function Fermer_app(Titre As String) As Boolean
- Dim handle As Long, thread As Long, proc_handle As Long
- handle = FindWindow(vbNullString, Titre)
- If handle = 0 Then Fermer_app = False: Exit Function
- GetWindowThreadProcessId handle, thread
- proc_handle = OpenProcess(PROCESS_TERMINATE, False, thread)
- TerminateProcess proc_handle, 4
- Fermer_app = True
- reloader_explorer
- End Function
- Public Function GetProcessTitle(hwnd As Long)
- Dim Str As String
- Str = String$(GetWindowTextLength(hwnd) + 1, Chr$(0))
- GetWindowText hwnd, Str, Len(Str)
- GetProcessTitle = Str
- End Function
-
- 'pas de moi (mais je l'ai amélioré) :
- Public Function listedestaches(frm As Form) As String
- On Error Resume Next
- Dim CurrWnd As Long
- Dim Length As Long
- Dim NomTache As String
- Dim Parent As Long
- Dim NbListe As String
- NbListe = 0
- CurrWnd = GetWindow(frm.hwnd, GW_HWNDFIRST)
- While CurrWnd <> 0
- Parent = GetParent(CurrWnd)
- Length = GetWindowTextLength(CurrWnd)
- NomTache = Space$(Length + 1)
- Length = GetWindowText(CurrWnd, NomTache, Length + 1)
- NomTache = Left$(NomTache, Len(NomTache) - 1)
- If Length <> 0 Then
- If NomTache <> Form1.Caption And NomTache <> "" Then
- If IsWindowVisible(CurrWnd) Then
- listedestaches = listedestaches & NomTache & vbCrLf
- End If
- End If
- End If
- CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
- DoEvents
- Wend
- End Function
- 'SÉCURITÉ CAR SI ON FERME UN DOSSIER, EXPLORER SE FERME ;-)
- Sub reloader_explorer()
- On Error Resume Next
- Dim CurrWnd As Long
- Dim Length As Long
- Dim NomTache As String
- Dim Parent As Long
- Dim NbListe As String
- Dim listedestaches
- NbListe = 0
- listedestaches = ""
- CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
- While CurrWnd <> 0
- Parent = GetParent(CurrWnd)
- Length = GetWindowTextLength(CurrWnd)
- NomTache = Space$(Length + 1)
- Length = GetWindowText(CurrWnd, NomTache, Length + 1)
- NomTache = Left$(NomTache, Len(NomTache) - 1)
- If Length <> 0 Then
- If NomTache <> Form1.Caption And NomTache <> "" Then
- If IsWindowVisible(CurrWnd) Then
- listedestaches = listedestaches & NomTache & vbCrLf
- End If
- End If
- End If
- CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
- DoEvents
- Wend
- If InStr(1, listedestaches, "Program Manager") <= 1 Then
- ouvrirexp
- End If
- End Sub
- Sub ouvrirexp()
- Dim fso As FileSystemObject, fold
- Set fso = New FileSystemObject
- fold = fso.GetSpecialFolder(WindowsFolder)
- If Right(fold, 1) = "\" Then
- Else
- fold = fold & "\"
- End If
- Shell fold & "explorer.exe"
- End Sub
-
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Const Fermer = &H10
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Public Function GetHandle(Titre As String) As Long
GetHandle = FindWindow(vbNullString, Titre)
End Function
Public Sub SetTitle(hwnd As Long, texte As String)
SetWindowText hwnd, texte
End Sub
Public Function IsAppRunning(Titre As String) As Boolean
Dim handle
handle = FindWindow(vbNullString, Titre)
If handle = 0 Then IsAppRunning = False Else: IsAppRunning = True
End Function
Public Function Fermer_app(Titre As String) As Boolean
Dim handle As Long, thread As Long, proc_handle As Long
handle = FindWindow(vbNullString, Titre)
If handle = 0 Then Fermer_app = False: Exit Function
GetWindowThreadProcessId handle, thread
proc_handle = OpenProcess(PROCESS_TERMINATE, False, thread)
TerminateProcess proc_handle, 4
Fermer_app = True
reloader_explorer
End Function
Public Function GetProcessTitle(hwnd As Long)
Dim Str As String
Str = String$(GetWindowTextLength(hwnd) + 1, Chr$(0))
GetWindowText hwnd, Str, Len(Str)
GetProcessTitle = Str
End Function
'pas de moi (mais je l'ai amélioré) :
Public Function listedestaches(frm As Form) As String
On Error Resume Next
Dim CurrWnd As Long
Dim Length As Long
Dim NomTache As String
Dim Parent As Long
Dim NbListe As String
NbListe = 0
CurrWnd = GetWindow(frm.hwnd, GW_HWNDFIRST)
While CurrWnd <> 0
Parent = GetParent(CurrWnd)
Length = GetWindowTextLength(CurrWnd)
NomTache = Space$(Length + 1)
Length = GetWindowText(CurrWnd, NomTache, Length + 1)
NomTache = Left$(NomTache, Len(NomTache) - 1)
If Length <> 0 Then
If NomTache <> Form1.Caption And NomTache <> "" Then
If IsWindowVisible(CurrWnd) Then
listedestaches = listedestaches & NomTache & vbCrLf
End If
End If
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Wend
End Function
'SÉCURITÉ CAR SI ON FERME UN DOSSIER, EXPLORER SE FERME ;-)
Sub reloader_explorer()
On Error Resume Next
Dim CurrWnd As Long
Dim Length As Long
Dim NomTache As String
Dim Parent As Long
Dim NbListe As String
Dim listedestaches
NbListe = 0
listedestaches = ""
CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
While CurrWnd <> 0
Parent = GetParent(CurrWnd)
Length = GetWindowTextLength(CurrWnd)
NomTache = Space$(Length + 1)
Length = GetWindowText(CurrWnd, NomTache, Length + 1)
NomTache = Left$(NomTache, Len(NomTache) - 1)
If Length <> 0 Then
If NomTache <> Form1.Caption And NomTache <> "" Then
If IsWindowVisible(CurrWnd) Then
listedestaches = listedestaches & NomTache & vbCrLf
End If
End If
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Wend
If InStr(1, listedestaches, "Program Manager") <= 1 Then
ouvrirexp
End If
End Sub
Sub ouvrirexp()
Dim fso As FileSystemObject, fold
Set fso = New FileSystemObject
fold = fso.GetSpecialFolder(WindowsFolder)
If Right(fold, 1) = "\" Then
Else
fold = fold & "\"
End If
Shell fold & "explorer.exe"
End Sub
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Problème de process [ par Xentor ]
Bonjour,Je voudrais savoir s'il est possible d'obtenir la liste des adresses mémoires allouées à un process...
HELP / liste des process sur un serveur [ par keopsk ]
Bonjour,Comment peut on faire pour lire les process sur un serveur sans passer par WMI ?Merci d'avance
Tuer un process [ par nicobou ]
Bonjour,je cherche à tuer un process précis à partir de son PID. J'arrive à récupérer la liste des process qui tournent, récupérer leur ID, mais je ne
Lancer un process avec des droits particuliers [ par cyrilp ]
Bonjour,J'aimerai savoir comment faire avec les API windows (NT) pour lancer une application sous un compte particulier.Par exemple, je suis connecté
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 Sous Win2k d'une app lancée avec shell() [ par 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 q
|
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
|