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); } } } }
這樣就可以獲得句柄進行隱藏收集系統信息的彈窗