gpt4 book ai didi

windows - 如何在运行批处理脚本时获取当前事件窗口?

转载 作者:可可西里 更新时间:2023-11-01 13:50:42 25 4
gpt4 key购买 nike

我有一个批处理脚本,我想用热键运行,这个脚本应该在事件窗口中执行一些操作(例如,创建一组特定的文件夹,或者将文件夹内文件的所有名称小写) .因此脚本在调用时需要引用事件窗口。

我试图将别名的“开始于”字段留空,但回显 %cd% 总是打印“C:\Windows\System32”而不是当前事件窗口。

最佳答案

您可以使用 user32.dll 的 pinvoke 查找哪个进程将窗口置于前台。我在脚本中对 system.window.forms.sendkeys 方法使用了这个技巧:

Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@

$a = [tricks]::GetForegroundWindow()

get-process | ? { $_.mainwindowhandle -eq $a } # in my case:

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------

161 7 13984 15820 91 9,75 7720 Console

关于windows - 如何在运行批处理脚本时获取当前事件窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9722252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com