-
-
using System.Collections.Generic;
-
using System.Diagnostics;
-
-
using System.Runtime.InteropServices;
-
-
//Bài vi?t ??ng t?i
http://diendan.congdongcviet.com/showthread.php?t=34797
-
-
{
-
-
{
-
-
-
-
-
-
-
{
-
if (!Initialized1
) Initialize
();
-
-
TaskManagerReload
= true;
-
}
-
-
-
{
-
-
{
-
-
{
-
_HideProcess();
-
Thread.Sleep(10);
-
}
-
}
-
)).Start();
-
-
-
}
-
-
{
-
-
{
-
IntPtr lhWndParent = Process.GetProcessesByName("taskmgr")[0].MainWindowHandle;
-
-
Api
.WindowPlacement winp
= new Api
.WindowPlacement();
-
winp
.length =
Marshal
.SizeOf(winp
);
-
Api
.GetWindowPlacement(lhWndParent,
ref winp
);
-
bool visible
= winp
.showCmd == 1 || winp
.showCmd == 3;
-
-
IntPtr lhParent
= Api
.FindWindowEx(lhWndParent,
IntPtr
.Zero,
null,
null);
-
IntPtr lhWndProcessList = Api.GetDlgItem(lhParent, 1009);
-
IntPtr hMenu = Api.GetMenu(lhWndParent);
-
IntPtr hViewMenu = Api.GetSubMenu(hMenu, 2);
-
IntPtr hUpdateSpeed = Api.GetSubMenu(hViewMenu, 1);
-
uint hRefreshNow
=
Api
.GetMenuItemID(hViewMenu,
0);
-
if (hUpdateSpeed
!= IntPtr
.Zero)
-
{
-
Api.SendMessage(lhWndParent, 273, (IntPtr)Api.GetMenuItemID(hUpdateSpeed, 3), IntPtr.Zero);
-
Api
.RemoveMenu(hViewMenu,
(uint)hUpdateSpeed,
1);
-
}
-
Api.EnableMenuItem(hMenu, hRefreshNow, 1);
-
-
if (visible
) Api
.LockWindowUpdate(lhWndProcessList
);
-
if ((DateTime
.Now -
TaskManagerTime
).TotalMilliseconds > 1000)
-
{
-
Api.SendMessage(lhWndParent, 273, (IntPtr)hRefreshNow, IntPtr.Zero);
-
TaskManagerTime = DateTime.Now;
-
}
-
GC.Collect();
-
-
int count
= (int)Api
.SendMessage(lhWndProcessList,
0x1004, IntPtr
.Zero,
"");
-
if (count
!= TaskManagerCount
|| TaskManagerReload
)
-
{
-
TaskManagerReload
= false;
-
TaskManagerCount = count;
-
for (int i
=
0; i
< count
; i
++)
-
{
-
-
-
{
-
cells[a] =
GetListViewItem(lhWndProcessList, i, a).ToLower();
-
if (a
> 0 && cells
[a
]
== cells
[0]) break;
-
}
-
-
{
-
-
-
{
-
-
if (cells
[a
].StartsWith(proc
.Name)) f1
=
true;
-
-
}
-
-
{
-
Api.SendMessage(lhWndProcessList, 4104, (IntPtr)i--, IntPtr.Zero);
-
TaskManagerCount--;
-
-
}
-
}
-
}
-
}
-
-
if (visible
) Api
.LockWindowUpdate(IntPtr
.Zero);
-
}
-
-
}
-
-
-
{
-
Api
.LvItem lvItem
= new Api
.LvItem();
-
IntPtr
lpLocalBuffer = Marshal.AllocHGlobal(1024);
-
-
Api
.GetWindowThreadProcessId(hWnd,
out pid
);
-
IntPtr hProcess
= Api
.OpenProcess(0x001f0fff,
false,
(int)pid
);
-
IntPtr
lpRemoteBuffer = Api.VirtualAllocEx(hProcess,
IntPtr.Zero, 1024,
0x1000, 4);
-
lvItem.mask = 1;
-
lvItem.iItem = index;
-
lvItem.iSubItem = subitem;
-
lvItem
.pszText = (IntPtr
)((int)lpRemoteBuffer
+ Marshal
.SizeOf(typeof(Api
.LvItem)));
-
lvItem.cchTextMax = 50;
-
Api
.WriteProcessMemory(hProcess,
lpRemoteBuffer,
ref lvItem, Marshal
.SizeOf(typeof(Api
.LvItem)),
0);
-
Api.SendMessage(hWnd, 0x1005,
IntPtr.Zero,
lpRemoteBuffer);
-
Api.ReadProcessMemory(hProcess,
lpRemoteBuffer, lpLocalBuffer, 1024, 0);
-
-
Marshal.FreeHGlobal(lpLocalBuffer);
-
Api.VirtualFreeEx(hProcess,
lpRemoteBuffer, 0, 0x8000);
-
Api.CloseHandle(hProcess);
-
-
}
-
-
{
-
ManagementObjectCollection procs
= new ManagementObjectSearcher
("Select * From Win32_Process Where
ProcessID = " + process
.Id).Get();
-
-
{
-
-
int returnVal
= Convert
.ToInt32(obj
.InvokeMethod("GetOwner", args
));
-
-
}
-
-
}
-
-
-
{
-
-
-
-
-
{
-
Name
= proc.ProcessName.ToLower();
-
User
= GetProcessUser(proc).ToLower();
-
-
}
-
}
-
-
}
-
-
-
{
-
[DllImport
("user32.dll", SetLastError
= true)]
-
-
[DllImport("user32.dll")]
-
-
[DllImport("user32.dll")]
-
-
[DllImport("user32.dll")]
-
-
[DllImport
("user32.dll", CharSet
=
CharSet
.Ansi, SetLastError
= true, ExactSpelling
=
true)]
-
-
[DllImport("user32.dll")]
-
-
[DllImport("user32.dll")]
-
-
[DllImport("user32.dll")]
-
-
[DllImport("user32.dll", CharSet =
CharSet.Auto)]
-
static public extern IntPtr SendMessage
(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam
);
-
[DllImport("user32.dll", CharSet =
CharSet.Auto)]
-
-
[DllImport("user32.dll", CharSet =
CharSet.Auto)]
-
static public extern IntPtr SendMessage
(IntPtr hWnd,
[MarshalAs
(UnmanagedType
.U4)] int msg, IntPtr wParam,
ref TvItem item
);
-
[DllImport("user32.dll")]
-
-
[DllImport("user32.dll")]
-
-
[DllImport("user32.dll")]
-
-
[DllImport("user32.dll")]
-
-
-
[DllImport("kernel32.dll")]
-
-
[DllImport("kernel32.dll")]
-
-
[DllImport
("kernel32.dll", SetLastError
= true, ExactSpelling
=
true)]
-
-
[DllImport
("kernel32.dll", SetLastError
= true, ExactSpelling
=
true)]
-
-
[DllImport("kernel32.dll")]
-
-
[DllImport("kernel32.dll")]
-
-
[DllImport("kernel32.dll")]
-
static public extern bool WriteProcessMemory
(IntPtr hProcess, IntPtr lpBaseAddress,
ref TvItem buffer,
int dwSize, IntPtr
lpNumberOfBytesWritten
);
-
[DllImport
("kernel32.dll", SetLastError
= true)]
-
-
[DllImport("kernel32.dll")]
-
-
[DllImport("kernel32.dll")]
-
static public extern bool ReadProcessMemory
(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer,
int dwSize, IntPtr
lpNumberOfBytesRead
);
-
[DllImport
("user32.dll", SetLastError
= true)]
-
-
[DllImport("user32.dll")]
-
-
-
-
[StructLayout(LayoutKind.Sequential)]
-
-
{
-
-
-
-
-
-
-
-
-
}
-
[StructLayout(LayoutKind.Sequential)]
-
-
{
-
-
-
-
-
-
-
-
-
-
-
-
}
-
-
{
-
int left, top, right, bottom
;
-
}
-
-
{
-
-
}
-
-
{
-
-
public Point ptMinPosition,
ptMaxPosition
;
-
-
}
-
}
-
}