zoukankan      html  css  js  c++  java
  • 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);
                }
            }
        }
    }

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

  • 相关阅读:
    并发编程bug的源头
    lambda表达式
    如何学习并发编程
    开篇词
    试述软件的概念和特点?软件复用的含义?构件包括哪些?
    软件生存周期及其模型是什么?
    一台客户端有三百个客户与三百个客户端有三百个客户对服务器施压,有什么区别?
    在搜索引擎中输入汉字就可以解析到对应的域名,请问如何用LoadRunner进行测试。
    给你一个网站,你如何测试?
    你在测试中发现了一个bug,但是开发经理认为这不是一个bug,你应该怎样解决?
  • 原文地址:https://www.cnblogs.com/javier520/p/10671768.html
Copyright © 2011-2022 走看看