本帖最后由 ivor 于 2019-3-3 10:15 编辑
powershell- #检测指定cmd窗口是否为活动窗口,修改("ConsoleWindowClass","命令提示符") 检测指定程序
- Add-Type @"
- using System.Runtime.InteropServices;
- public class WinApi {
- [DllImport("user32.dll")]
- public static extern int FindWindow(string lpClassName, string lpWindowName);
-
- [DllImport("user32.dll")]
- public static extern int GetForegroundWindow();
- }
-
- "@
-
- while($true){
- if([WinApi]::FindWindow("ConsoleWindowClass","命令提示符") -ne [WinApi]::GetForegroundWindow()){
- #code here
- Write-Host cmd is not font window.
- }else{
- #code here
- Write-Host cmd is font window.
- }
- sleep 1
- }
复制代码
|