gpt4 book ai didi

c# - 如何检测从 C# 启动的新应用程序?

转载 作者:太空宇宙 更新时间:2023-11-03 19:30:29 25 4
gpt4 key购买 nike

我有一个用于 C# 的 .dll 库,它喜欢在启动时弹出“欢迎”屏幕。此屏幕在任务管理器中显示为应用程序。

有什么方法可以自动检测正在启动的应用程序/表单并关闭它吗?

谢谢! :)

最佳答案

这里是我们将监视和关闭指定窗口的简单控制台应用程序

class Program
{
static void Main(string[] args)
{
while(true)
{
FindAndKill("Welcome");
Thread.Sleep(1000);
}
}

private static void FindAndKill(string caption)
{
Process[] processes = Process.GetProcesses();
foreach (Process p in processes)
{
IntPtr pFoundWindow = p.MainWindowHandle;
StringBuilder windowText = new StringBuilder(256);

GetWindowText(pFoundWindow, windowText, windowText.Capacity);
if (windowText.ToString() == caption)
{
p.CloseMainWindow();
Console.WriteLine("Excellent kill !!!");
}
}
}

[DllImport("user32.dll", EntryPoint = "GetWindowText",ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowText(IntPtr hWnd,StringBuilder lpWindowText, int nMaxCount);
}

关于c# - 如何检测从 C# 启动的新应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5271775/

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