上次已经能够打开win10jh.exe这个软件了,这次我们来研究如何找到这个窗体,然后再对其进行操作。
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace jhwin
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//1、引用API
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
private void Form1_Load(object sender, EventArgs e)
{
label2.Text = "等待激活软件运行...";
//2、允许在线程中更改控件值
CheckForIllegalCrossThreadCalls = false;
//3、在线程中运行 RunJHexe ,好观察结果
Thread t = new Thread(RunJHexe);
t.IsBackground = true;
t.Start();
}
//运行激活程序
void RunJHexe()
{
//临时文件夹位置
var tempPath = Path.Combine(Path.GetTempPath(), "win10jh.exe");
//将文件写到临时文件夹位置
File.WriteAllBytes(tempPath, Resource1.win10jh);
//建立文件信息
var info = new ProcessStartInfo(tempPath);
//这里选false的话,需要提升本调试程序权限
info.UseShellExecute = true;
//启动程序
Process.Start(info);
//4、观察 win10jh.exe 是否已经运行了。
FindJHWin();
}
void FindJHWin()
{
bool OK;
OK = false;
while (!OK)
{
//主窗口标题 为 win10jh.exe
IntPtr startwin = FindWindow(null, "win10jh.exe");
if (startwin != IntPtr.Zero)
{
label2.Text += "已运行!";
OK = true;
}
}
}
}
}
页面更新:2024-03-13
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号