C#操作句柄

1、直接上例子吧:收集系统信息msinfo32时,会有一个弹窗,现在要隐藏该弹窗,首先看没有通过句柄隐藏弹窗的现象

2、收集系统信息导入到一个位置

代码:

Process[] msinfo32process;//创建一个PROCESS类数组
msinfo32process = Process.GetProcesses();//获取当前任务管理器所有运行中程序
foreach (Process proces in msinfo32process)//遍历若存在msinfo21.exe则杀掉
{
     if (proces.ProcessName == "msinfo32.exe")
     {
            proces.Kill();
     }
}
//通过调用CMD命令进行系统信息导出为一个文件 Common.CmdExcute("msinfo32 /nfo C:\\tmp\\msinfo32.nfo");

3、下面通过操作句柄进行隐藏收集信息框

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Threading; using System.Runtime.InteropServices; namespace test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Process[] msinfo32process;//创建一个PROCESS类数组 msinfo32process = Process.GetProcesses();//获取当前任务管理器所有运行中程序 foreach (Process proces in msinfo32process)//遍历  { if (proces.ProcessName == "msinfo32.exe") { proces.Kill(); } } Thread msinfo32 = new Thread(msinfo); msinfo32.Start();  } private static void msinfo() { Common.CmdExcute("msinfo32 /nfo C:\\vDesk\\msinfo32.nfo"); } public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32")] private static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string windowName); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); private static void whatr() { bool stop = true; while (stop) { //Sometimes System.Windows.Forms.Application.ExecutablePath works for the caption depending on the system you are running under. IntPtr hWnd = FindWindow(null, "系统信息"); //put your console window caption here IntPtr hWnd_en = FindWindow(null, "System Information"); if (hWnd != IntPtr.Zero) { //Hide the window IntPtr child = FindWindowEx(hWnd, IntPtr.Zero, "#32770", "系统信息"); ShowWindow(hWnd, 0); // 0 = SW_HIDE if (child != IntPtr.Zero) { ShowWindow(child, 0); // 0 = SW_HIDE //Notice:设置之后退出线程 stop = false; } } else if (hWnd_en != IntPtr.Zero) { IntPtr child_en = FindWindowEx(hWnd_en, IntPtr.Zero, "#32770", "System Information"); ShowWindow(hWnd_en, 0); // 0 = SW_HIDE if (child_en != IntPtr.Zero) { ShowWindow(child_en, 0); // 0 = SW_HIDE //Notice:设置之后退出线程 stop = false; } } Thread.Sleep(50); } } } }

这样就可以获得句柄进行隐藏收集系统信息的弹窗

转载于:https://www.cnblogs.com/javier520/p/10671768.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值