复制内容到剪贴板
程序代码

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");
}
}
}
}
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");
}
}
}
}