当前位置: 首页 > news >正文

自动化RPA开发 --获取所有窗口信息和进程信息

场景

准备做一个RPA工具,可以从桌面和浏览器选择元素,获取窗口信息和进程信息是必要的,因为获取了窗口信息和进程,可用对程序做一些想要的操作。

coding

工具类

/*** Windows系统工具类*/
public class WinOsUtils {static final User32 user32 = User32.INSTANCE;/*** 获取当前系统下所有的Windows窗口信息* @return*/public static List<WindowInfo> allWindows() {final List<WindowInfo> windows = new ArrayList<>();boolean result = user32.EnumWindows(new WinUser.WNDENUMPROC() {public boolean callback(final WinDef.HWND hwnd, final Pointer data) {if (user32.IsWindowVisible(hwnd)) {IntByReference windowPid = new IntByReference();user32.GetWindowThreadProcessId(hwnd, windowPid);String windowTitle = getWindowTitle(hwnd);windows.add(new WindowInfo(hwnd, windowPid.getValue(), windowTitle));}return true;}},null);/* Handle errors. */if (!result && Kernel32.INSTANCE.GetLastError() != 0) {throw new RuntimeException("Couldn't enumerate windows.");}/* Return the window list. */return windows;}/*** 过窗口句柄来获取指定窗口的标题文本,通常用于窗口管理、自动化测试、或需要识别和操作特定窗口的应用程序中。* @param hWnd 句柄* @return 窗口标题*/public static String getWindowTitle(WinDef.HWND hWnd) {char[] text = new char[1024];int length = user32.GetWindowText(hWnd, text, 1024);return length > 0 ? new String(text, 0, length) : null;}
}

窗口信息


/*** 窗口信息*/
public class WindowInfo {/*** 句柄 唯一定义APP的因素*/public WinDef.HWND hwnd;/*** 进程id*/public int pid;/*** 标题*/public String title;public WindowInfo(WinDef.HWND hwnd, int pid, String title) {super();this.hwnd = hwnd;this.pid = pid;this.title = title;}public WinDef.HWND getHwnd() {return hwnd;}public int getPid() {return pid;}public String getTitle() {return title;}
}

进程信息

/*** 系统进程信息* @Author: Herche Jane* @Date: 2023/10/16*/
public class ProcessInfo {/*** 进程名称*/private String name;/*** pid*/private Integer pid;public ProcessInfo(String name,Integer pid){this.name = name;this.pid = pid;}public String getName() {return name;}public Integer getPid() {return pid;}}

结束

这样我们获取了所有的窗口信息和进程信息了,后面有利于我们RPA软件的开发。

http://www.lryc.cn/news/197525.html

相关文章:

  • 【Qt之布局】QVBoxLayout、QHBoxLayout、QGridLayout、QFormLayout介绍及使用
  • 【计算机毕业设计】python在线课程培训学习考试系统637r7-PyCharm项目
  • vue3后台管理系统之登录界面和业务的实现
  • GEE19:基于Landsat8的常见的植被指数逐年获取
  • Python【多分支实际应用的练习】
  • LeetCode 343. 整数拆分(动态规划)
  • C++对象模型(12)-- 构造函数语义学:构造函数
  • [23] T^3Bench: Benchmarking Current Progress in Text-to-3D Generation
  • linux系统如何定时关机
  • 构建高性能物联网数据平台:EMQX和CnosDB的完整教程
  • 【vim 学习系列文章 11 -- vim filetype | execute | runtimepath 详细介绍】
  • [备忘]WindowsLinux上查看端口被什么进程占用|端口占用
  • 函数的扩展
  • Cypress安装使用
  • 怎么把图片改成jpg格式?
  • [一带一路金砖 2023 CTF]Crypto
  • FPGA【Verilog语法】
  • Flume 整合 Kafka
  • VUE:侧边弹出栏组件,组件中有树状图,搜索框可筛选树状图节点,可收缩
  • 如何使用pytorch定义一个多层感知神经网络模型——拓展到所有模型知识
  • 为什么引入SVG文件,给它定义属性不生效原理分析
  • Integer包装类常用方法和属性
  • 基于Spring boot轻松实现一个多数据源框架
  • vue前端实现打印功能并约束纸张大小---调用浏览器打印功能打印页面部分元素并固定纸张大小
  • 音乐播放器蜂鸣器ROM存储歌曲verilog,代码/视频
  • Arduino Nano 引脚复用分析
  • Go 函数多返回值错误处理与error 类型介绍
  • 数论分块
  • 宏任务与微任务,代码执行顺序
  • 正方形(Squares, ACM/ICPC World Finals 1990, UVa201)rust解法