欢迎光临

木子屋

标题: C#查找运行中的应用程序并将其显示到前端

作者: dnawo

日期: 2020-03-28 11:59 PM

分类: Win编程

内容: 复制内容到剪贴板 程序代码using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace ConsoleApp1
{
class Program
{
private const int SW_HIDE = 0;
private const int SW_NORMAL = 1;
private const int SW_MAXIMIZE = 3;
private const int SW_SHOWNOACTIVATE = 4;
private const int SW_SHOW = 5;
private const int SW_MINIMIZE = 6;
private const int SW_RESTORE = 9;
private const int SW_SHOWDEFAULT = 10;
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
static void Main(string[] args)
{
string processName = "WindowsFormsApp1"; //要查找的进程名称
Process[] processes = Process.GetProcessesByName(processName);
if(processes.Length>0)
{
ShowWindowAsync(processes[0].MainWindowHandle, SW_SHOW);
SetForegroundWindow(processes[0].MainWindowHandle);
}
else
{
Console.WriteLine("程序没有运行！");
Console.ReadKey();
//Process.Start("D:\WindowsFormsApp1.exe");
}
}
}
}

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.674 ms

返回

标题: C#查找运行中的应用程序并将其显示到前端

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.674 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.705 ms

返回