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);
}
}
}
}
这样就可以获得句柄进行隐藏收集系统信息的弹窗
C#操作句柄的更多相关文章
- 操作句柄Handle(7)
可以将Handle理解成访问对象的一个“句柄”.垃圾回收时对象可能被移动(对象地址发生改变),通过Handle访问对象可以对使用者屏蔽垃圾回收细节. Handle涉及到的相关类的继承关系如下图所示. ...
- VMware View 要求操作句柄的状态错误
win10系统安装的VMware-viewclient,版本是
- (10)odoo控制器操作
-----------------更新时间11:17 2016-09-18 星期日 完善讲解17:44 2016-02-17 星期三-----------------* 控制器Controlle ...
- (05)odoo数据库和业务操作
以一个例子开头* To-do 向导 # 配置文件 __openerp_.py: { 'name': 'To-do Tasks Management Assistant' ...
- 使用开源库MagicalRecord操作CoreData
1. 将 MagicalRecord 文件夹拖入到工程文件中,引入 CoreData.frame 框架 2. 在 .pch 文件中引入头文件 CoreData+MagicalRecord.h 注: ...
- Python之路----文件操作
文件操作 1.能调用方法的一定是对象,比如数值.字符串.列表.元组.字典,甚至文件也是对象,Python中一切皆为对象. str1 = 'hello' str2 = 'world' str3 = ' ...
- Windows中的句柄
(一)句柄 在程序设计中,句柄(handle)是一种特殊的智能指针.当一个应用程序要引用其他系统(如数据库.操作系统)所管理的内存块或对象时,就要使用句柄. 句柄与普通指针的区别在于,指针包含的是引用 ...
- Swift3.0服务端开发(四) MySQL数据库的连接与操作
本篇博客我们来聊聊MySQL数据库的连接与操作.如果你本地没有MySQL数据库的话,需要你先安装MySQL数据库.在Mac OS中使用brew包管理器进行MySQL的安装是及其方便的.安装MySQL的 ...
- C 标准库基础 IO 操作总结
其实输入与输出对于不管什么系统的设计都是异常重要的,比如设计 C 接口函数,首先要设计好输入参数.输出参数和返回值,接下来才能开始设计具体的实现过程.C 语言标准库提供的接口功能很有限,不像 Pyth ...
随机推荐
- kubernetes滚动更新
系列目录 简介 当kubernetes集群中的某个服务需要升级时,传统的做法是,先将要更新的服务下线,业务停止后再更新版本和配置,然后重新启动并提供服务.如果业务集群规模较大时,这个工作就变成了一个挑 ...
- $modal 参数 以及 使用方法
$modal是一个可以迅速创建模态窗口的服务,创建部分页,控制器,并关联他们 $modal仅有一个方法open(options) templateUrl:模态窗口的地址 template:用于显示ht ...
- (Vue)vue模板语法
Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据.Vue.js 的核心是一个允许你采用简洁的模板语法来声明式的将数据渲染进 DOM 的系统. ...
- ipa验证错误问题总结
The following issues were found during validation.这个error的产生原因是因为代码中写的标示符或者方法名,与系统的命名空间冲突. 具体是哪个标示符或 ...
- Microsoft.AspNetCore.Identity 使用 mysql 报错处理
1.使用mysql 首先要确定mysql connector 支的版本,正面是链接 https://dev.mysql.com/doc/connector-net/en/connector-net-e ...
- appium导入哪些java模块
简单介绍 讲解一个appium测试脚本需要导入哪些java模块. 导入的java模块 明确两点信息: 一个脚本需要讲清楚测试环境:1.自动化平台方面,测试的平台是什么(appium或者selendro ...
- AndroidDragAndDrop.java
以下代码使用ApiDemos-debug.apk进行测试 package com.saucelabs.appium; import io.appium.java_client.AppiumDriver ...
- jquery特效(2)—选项卡
最近公司有个页面正好用到了选项卡,我就写了一下,感觉还不错,都挺简单的. 下面来看动态效果: 一.主体程序 <!DOCTYPE html> <html> <head> ...
- SDUT OJ 之 1571 《人品,有没有?》 字符串的处理问题
人品,有木有? Time Limit: 1000ms Memory limit: 32768K 有疑问?点这里^_^ 题目描述 新一届的山东理工大学ACM网络擂台赛就要开始啦!听说晋级的选手有机 ...
- Codeforces Round #385 (Div. 2) Hongcow Builds A Nation —— 图论计数
题目链接:http://codeforces.com/contest/745/problem/C C. Hongcow Builds A Nation time limit per test 2 se ...