切换到另一个正在运行的进程
有人可以解释一下我将如何通过 C# 切换到另一个正在运行的程序吗?
例如,如果我创建一个带有按钮事件的新应用程序 - 我想使用该按钮来调用一个打开的应用程序,例如 Internet Explorer 或 Word。
我知道如何启动应用程序,但不太确定如何在它们已经运行时调用它们。
这是迄今为止我们一直在努力的事情:
if (System.Diagnostics.Process.GetProcessesByName("ExternalApplication").Length >= 1)
{
foreach (Process ObjProcess in System.Diagnostics.Process.GetProcessesByName("ExternalApplication"))
{
ActivateApplication(ObjProcess.Id);
Interaction.AppActivate(ObjProcess.Id);
SendKeys.SendWait("~");
}
}
Can someone please explain how I would go about switching to another running program via C#?
For example if i create a new application with a button event - i would like to use the button to say call an open application like internet explorer or word.
I know how to start applications but not quite sure how to call them when they are already running.
This is what have been working on so far:
if (System.Diagnostics.Process.GetProcessesByName("ExternalApplication").Length >= 1)
{
foreach (Process ObjProcess in System.Diagnostics.Process.GetProcessesByName("ExternalApplication"))
{
ActivateApplication(ObjProcess.Id);
Interaction.AppActivate(ObjProcess.Id);
SendKeys.SendWait("~");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我必须解决类似的问题,并且我必须执行一些 pInvoking 才能完成它。请参阅下面的代码。
I had to solve a similar problem, and I had to do some pInvoking to get it done. See code below.
下面的代码对我有用
如果窗口最小化,上面的代码将不起作用
代码:
用法:
below code worked for me
above code doesn't work if window is minimized
code:
usage:
我正在使用以下内容,但我认为没有在第 31 行正确定义进程名称。
I am using the following but i dont think have defined the process name correctly on line 31.