网上的都不能用啊…全是未完成代码或者兼容性极差的代码。自己写呗。
任务管理器实际上是用了SysListView32控件,所以发点消息就可以解决(但是发点消息也没那么容易)
ListView_GetItemText宏只是对当前进程有效,对远程进程是无效的,但是label之类的控件gettext对远程进程是有效的,具体的可以看《Windows via C/C++》中文第5版第579面(只是记得有这个特性,但不记得书中多少面提到了。特地翻书找到了这一面,不容易)。

成品:http://download.csdn.net/download/wwh1004/10244689

比较关键的代码在下面

/// <summary>
/// 读取字符串,如果读取到非托管进程中,并且读取为LPSTR LPWSTTR BSTR等字符串类型,请自行转换为byte[]并使用<see cref="ReadBytes(uint, Pointer, byte[])"/>,<see cref="ReadBytes(uint, IntPtr, byte[])"/>
/// </summary>
/// <param name="processHandle">进程句柄</param>
/// <param name="addr">地址</param>
/// <param name="value">值</param>
/// <param name="bufferSize">缓存大小</param>
/// <param name="doubleZero">是否以2个\0结尾(比如LPWSTR以2个字节\0结尾,而LPSTR以1个字节\0结尾)</param>
/// <param name="encoding">编码</param>
/// <returns></returns>
internal static unsafe bool ReadStringInternal(IntPtr processHandle, IntPtr addr, out string value, int bufferSize, bool doubleZero, Encoding encoding)
{if (encoding == null)throw new ArgumentNullException(nameof(encoding) + "不能为null");if (bufferSize <= 0)throw new ArgumentOutOfRangeException(nameof(bufferSize) + "小于等于0");byte[] buffer;uint numberOfBytesRead;List<byte> bufferList;bool lastByteIsZero;buffer = null;numberOfBytesRead = 0;bufferList = new List<byte>(bufferSize);lastByteIsZero = false;for (int i = 0; i < int.MaxValue; i++){buffer = new byte[bufferSize];ReadProcessMemory(processHandle, addr + bufferSize * i, buffer, (uint)bufferSize, &numberOfBytesRead);//读取到缓存if ((int)numberOfBytesRead == bufferSize){//读取完整for (int j = 0; j < bufferSize; j++){if (buffer[j] == 0){//出现\0if (doubleZero){//如果双\0结尾if (lastByteIsZero)//上一个字节为\0goto addLastRange;if (j + 1 != bufferSize){//不是缓存区最后一个字节if (buffer[j + 1] == 0)//下一个字节也为\0goto addLastRange;}else//缓存读完,标记上一个字节为\0lastByteIsZero = true;}else//不是2个\0结尾,直接跳出goto addLastRange;}else{if (lastByteIsZero)//上一个字节为\0,但当前字节不是lastByteIsZero = false;}}}else if (numberOfBytesRead == 0){//读取失败value = null;return false;}else{//读取不完整for (int j = 0; j < (int)numberOfBytesRead; j++){if (buffer[j] == 0){//出现\0if (doubleZero){//如果双\0结尾if (lastByteIsZero)//上一个字节为\0goto addLastRange;if (j + 1 != (int)numberOfBytesRead && buffer[j + 1] == 0)//不是缓存区最后一个字节且下一个字节也为\0goto addLastRange;}else//不是2个\0结尾,直接跳出goto addLastRange;}else{if (lastByteIsZero)//上一个字节为\0,但当前字节不是lastByteIsZero = false;}}}bufferList.AddRange(buffer);};addLastRange:numberOfBytesRead -= doubleZero ? 2u : 1u;for (int i = 0; i < (int)numberOfBytesRead; i++)bufferList.Add(buffer[i]);if (encoding.CodePage == Encoding.Unicode.CodePage)buffer = bufferList.ToArray();elsebuffer = Encoding.Convert(encoding, Encoding.Unicode, bufferList.ToArray());fixed (void* p = &buffer[0])value = new string((char*)p);return true;
}/// <summary>
/// 在远程进程中读取结构
/// </summary>
/// <typeparam name="TStruct"></typeparam>
/// <param name="hWnd">控件句柄</param>
/// <param name="structure">读取出的结构体</param>
/// <param name="callbackBeforeRead">读取前回调方法</param>
/// <param name="callbackAfterRead">读取后回调方法</param>
/// <returns></returns>
public static unsafe bool ReadStructRemote<TStruct>(IntPtr hWnd, out TStruct structure, Func<IntPtr, IntPtr, bool> callbackBeforeRead, Func<IntPtr, IntPtr, bool> callbackAfterRead) where TStruct : IWin32ControlStruct
{uint processId;IntPtr hProcess;bool is64;IntPtr remoteAddr;structure = default(TStruct);processId = Process.GetProcessIdByHWnd(hWnd);//获取控件所在进程IDhProcess = OpenProcessRWQuery(processId);//打开进程if (hProcess == IntPtr.Zero)return false;if (!Process.Is64ProcessInternal(hProcess, out is64))return false;if (is64 && !Environment.Is64BitProcess)throw new NotSupportedException("目标进程为64位但当前进程为32位");try{remoteAddr = VirtualAllocEx(hProcess, IntPtr.Zero, structure.Size, MEM_COMMIT, PAGE_READWRITE);//在控件所在进程分配内存,用于储存structuretry{if (callbackBeforeRead != null)if (!callbackBeforeRead(hProcess, remoteAddr))return false;if (!ReadProcessMemory(hProcess, remoteAddr, structure.ToPointer(), structure.Size, null))//从远程进程取回到当前进程失败return false;if (callbackAfterRead != null)if (!callbackAfterRead(hProcess, remoteAddr))return false;return true;}finally{VirtualFreeEx(hProcess, remoteAddr, 0, MEM_RELEASE);//释放之前分配的内存}}finally{CloseHandle(hProcess);//关闭句柄}
}/// <summary>
/// 获取列表视图控件中Item的文本
/// </summary>
/// <param name="i">The index of the list-view item.</param>
/// <param name="iSubItem">The index of the subitem. To retrieve the item text, set iSubItem to zero.</param>
/// <returns></returns>
public unsafe string GetItemText(int i, int iSubItem)
{LVITEM item;IntPtr pStr;string text;text = null;pStr = IntPtr.Zero;item = new LVITEM{iSubItem = iSubItem,cchTextMax = 0x1000};Util.WriteStructRemote(Handle, ref item, (IntPtr hProcess, IntPtr addr) =>{pStr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, MEM_COMMIT, PAGE_READWRITE);//分配内存用于写入字符串if (pStr == IntPtr.Zero)return false;item.pszText = (char*)pStr;//设置缓存区地址return true;}, (IntPtr hProcess, IntPtr addr) =>{try{if (ListView_GetItemText(Handle, i, addr, 0x1000) == 0)return false;return MemoryIO.ReadStringInternal(hProcess, (IntPtr)item.pszText, out text, 0x1000, true);}finally{VirtualFreeEx(hProcess, pStr, 0, MEM_RELEASE);}});return text;
}

别的实现起来就挺简单了

using System;
using System.Threading;
using FastWin32.Control;
using FastWin32.Diagnostics;namespace 隐藏进程Demo
{static class Program{/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main(){RemoveItemLoop("chrome.exe", "conhost.exe", "RuntimeBroker.exe", "svchost.exe", "隐藏进程Demo.exe");}/// <summary>/// 移除循环/// </summary>/// <param name="name">进程名</param>private static void RemoveItemLoop(params string[] names){if (names == null || names.Length == 0)throw new ArgumentNullException();while (true){foreach (string name in names)RemoveItem(name);Thread.Sleep(100);}}/// <summary>/// 从任务管理器中移除进程/// </summary>/// <param name="name">进程名</param>/// <returns></returns>private static bool RemoveItem(string name){IntPtr hWnd;SysListView32 listView;int count;string text;hWnd = GetListViewHandle();if (hWnd == IntPtr.Zero)return false;listView = new SysListView32(hWnd);count = listView.GetItemCount();if (count == 0)return false;name = name.ToUpperInvariant();for (int i = count - 1; i >= 0; i--){text = listView.GetItemText(i, 0);if (text == null)continue;if (text.ToUpperInvariant() == name)listView.DeleteItem(i);}return true;}/// <summary>/// 获取任务管理器列表控件句柄/// </summary>/// <returns></returns>private static IntPtr GetListViewHandle(){IntPtr hWnd;if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1){//Win7hWnd = Window.FindWindow(null, "Windows 任务管理器");if (hWnd == IntPtr.Zero)return IntPtr.Zero;hWnd = Window.FindWindow(hWnd, IntPtr.Zero, null, "Processes");if (hWnd == IntPtr.Zero)return IntPtr.Zero;return Window.FindWindow(hWnd, IntPtr.Zero, "SysListView32", "进程");}else{//Win8.1 Win10 别的系统未适配hWnd = Window.FindWindow(null, "任务管理器");if (hWnd == IntPtr.Zero)return IntPtr.Zero;hWnd = Window.FindWindow(hWnd, IntPtr.Zero, null, "TaskManagerMain");if (hWnd == IntPtr.Zero)return IntPtr.Zero;hWnd = Window.FindWindow(hWnd, IntPtr.Zero, "DirectUIHWND", null);if (hWnd == IntPtr.Zero)return IntPtr.Zero;Window.EnumChildWindows(hWnd, (IntPtr hChildWnd) =>{hWnd = Window.FindWindow(hChildWnd, IntPtr.Zero, "SysListView32", null);if (hWnd == IntPtr.Zero)return true;elsereturn false;});return hWnd;}}}
}

去年写的放寒假才发出来,原因是作业太多,学习好累啊…

C#隐藏任务管理器中进程 支持win10 win8.1 win7相关推荐

  1. “任务管理器”中“进程”各个选项卡的含义

    "任务管理器"中"进程"各个选项卡的含义?           总结 PID(进程标识符) 唯一标识所运行进程的编号.           用户名     运行 ...

  2. “任务管理器”中“进程”各个选项卡的含义?

    问题描述 "任务管理器"中"进程"各个选项卡的含义? 总结 PID(进程标识符) 唯一标识所运行进程的编号. 用户名 运行该进程的用户帐户. 会话标识 标识进程 ...

  3. win10/win8换win7教程

    一 前言 重做系统相信很多小伙伴都get到了这个技能,U启动.大白菜.Ghost安装器-blablabla-一大堆.很多方法都可以帮助你重新换一个系统,但是在预装win8换win7的时候,小伙伴们可能 ...

  4. 微软统一打补丁的服务器,明白打补丁! 微软公布2月Win10/Win8.1/Win7更新详情

    IT之家讯 2月10日消息,微软今日凌晨向用户推送了2016年2月安全更新,现已公布本月更新详情.2016年2月共包含13项安全更新,其中前6项为严重级别,其余7项为重要级别. 受影响的操作系统和组件 ...

  5. win8 性能测试软件,Win10/Win8.1/Win7全方位性能评测大揭秘(3):应用性能

    操作系统存在的意义就是让众多的软件应用有发挥的平台,因此应用软件在系统中的表现也是评测一款系统性能的重要因素.测试者在此类测试中对当今主流软件的加载速度,以及压缩软件性能做了对比测试,Win10的表现 ...

  6. 联想预装Win10/Win8换Win7 教程 以及svn使用教程

    1.换系统教程 http://ideapad.it168.com/thread-4869510-1-1.html http://jingyan.baidu.com/article/08b6a591c8 ...

  7. 微软MSDN现Bug?非订阅用户可下载Win10/Win8/Win7等

    9月25日消息,我们都知道从微软官方MSDN网站下载资源需要订阅账户,今天国外论坛MDL网友发帖分享了一个小窍门,任何人都可以从微软MSDN网站中下载Win10/Win8.1/Win7/Office ...

  8. vb中如何在任务管理器里面隐藏应用程序进程

    '该模块用于在任务管理器中隐藏进程 Private Const STATUS_INFO_LENGTH_MISMATCH = &HC0000004 Private Const STATUS_AC ...

  9. VB在XP/2K 任务管理器的进程列表中隐藏当前进程

    新建一个模块,把以下代码复制进去,然后在load中调用即可实现隐藏当前进程的目的. Option Explicit '----------------------------------------- ...

  10. 获取 Windows 任务管理器中应用程序和进程 任务

    获取应用程序: #pragma once #include "afxcmn.h" /*判断窗口是否是正常运行还是未响应的*/ typedef   BOOL  (WINAPI *PR ...

最新文章

  1. 素材诊断分析助手_短视频运营必备的8款数据分析工具
  2. java 线程池ThreadPoolExecutor
  3. 解决Button在IE6、7下的自适应宽度问题
  4. 【工具】克隆题库(适用于所有以POJ2005-2017为模板的OJ平台)
  5. php实训总结00字,说明的比较细的php 正则学习实例
  6. EMA算法的C#实现
  7. 曲线曲面积分、重积分总结
  8. 缺失值填充5——AutoEncoder填充序列缺失值
  9. aws rds监控慢sql_AWS RDS SQL Server入门
  10. 算法设计分析(44页)
  11. hdu 1864 最大报销额 模型为简单的01背包
  12. 《图解算法》学习笔记之选择排序
  13. php laravel 相关收集
  14. 仿真技术在控制系统中的应用 ---飞机姿态控制仿真( 俯仰角)
  15. MXNet对含隐藏状态的循环神经网络(RNN)的实现
  16. HGIMDA:用于miRNA-疾病关联预测的异构图推断
  17. 反向的css动画,反向使用CSS动画(通过重置状态?)
  18. pycharm创建django项目及开发初准备
  19. Svchost.exe是病毒的两种情况
  20. 大数据技术学习推荐书籍(一)

热门文章

  1. 如何在前端html获取cookie
  2. 软件需求工程 高校教学平台 项目总结报告
  3. SqlServer2005使用top 100 PERCENT 无法排序的问题
  4. bzoj 3772 :精神污染 线段树+打标记 or 主席树
  5. 键盘调节台式计算机声音,台式电脑如何用键盘控制声音开关
  6. U-SEM体验模型——让游戏交互设计的维度更加清晰
  7. Linux下的数学工具Maxima 简明教程(上)
  8. excel 一列的数据除以另一列
  9. 给出某个时间段,要求以三十分钟为分割,统计出每三十分钟内数据的数量
  10. Swiper的安装及使用