C# 判断某程序是否运行

[DllImport("user32.dll")]

private static extern bool

SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]

private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

[DllImport("user32.dll")]

private static extern bool IsIconic(IntPtr hWnd);

// 消息函数

[DllImport("user32.dll", EntryPoint = "PostMessageA")]

public static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

[DllImport("user32.dll")]

public static extern IntPtr FindWindow(string strclassName, string strWindowName);

[DllImportAttribute("user32.dll")]

public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

public const int WM_SYSCOMMAND = 0x0112;

public const int SC_MAXIMIZE = 0xF030;

private string exeName = "SaoMiaoApp";

public void SetForm()

{

Process[] processes = Process.GetProcessesByName(exeName);

if (processes.Length > 0)

{

IntPtr hWnd = processes[0].MainWindowHandle;

if (IsIconic(hWnd))

ShowWindowAsync(hWnd, 9);// 9就是SW_RESTORE标志,表示还原窗体

//SendMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);

SetForegroundWindow(hWnd);

}

else

{

Process.Start(exeName + ".exe");

}

}

时间: 2024-08-08 09:29:28

C# 判断某程序是否运行的相关文章

C#判断某程序是否运行的方法

本文实例讲述了C#判断某程序是否运行的方法,分享给大家供大家参考. 具体实现方法如下: [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); [DllImp

Inno Setup安装、卸载时判断是否程序正在运行

var ErrorCode: Integer; IsRunning: Integer; // 安装时判断客户端是否正在运行 function InitializeSetup(): Boolean; begin Result :=true; //安装程序继续 IsRunning:=FindWindowByWindowName('E家人客户端'); while IsRunning<>0 do begin if Msgbox('安装程序检测到客户端正在运行.' #13#13 '您必须先关闭它然后单击

判断程序是否运行在管理员权限下

1.提出两个概念(成立条件是系统是Vista后续版本,这是因为引入了UAC) 一个是运行程序的账号是管理员账号 另一个是当前运行环境是管理员环境 2.判断程序是否运行在管理员权限,直接使用函数IsUserAnAdmin就可以判断 #include <ShlObj.h> #include <tchar.h> int _tmain() { BOOL bIsAdmin = IsUserAnAdmin(); if(bIsAdmin) _tprintf_s(_T("Run As a

C#:判断当前程序是否通过管理员运行

原文:C#:判断当前程序是否通过管理员运行 public bool IsAdministrator() { WindowsIdentity current = WindowsIdentity.GetCurrent(); WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current); return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator); } 转载声

判断 php 程序是通过什么方式运行的 (浏览器,还是命令行)

php 程序既可以通过浏览器来访问(一般是 apache.nginx等服务器), 也可以通过命令行来直接运行(cli 执行) 如果需要判断 当前程序是以何种方式来执行,应该怎样判断呢,使用:php_sapi_name() 方法, 示例: <?php function is_cli_mode() { $sapi_type = php_sapi_name(); if (isset($sapi_type) && substr($sapi_type, 0, 3) == 'cli') { re

[转]Delphi中,让程序只运行一次的方法

program onlyRunOne; uses Forms,Windows,SysUtils, Dialogs, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} var myMutex:HWND; begin myMutex:=CreateMutex(nil,false,'11111'); //名称只能全系统唯一. if WaitForSingleObject(myMutex,0)<>wait_TimeOut then begin Application.I

Windows程序内部运行机制

Windows程序内部运行机制 一.        API与SDK Windows操作系统提供了各种各样的函数,以方便我们开发Windows应用程序,这些函数是Windows操作系统提供给应用程序编程的接口(Application Programming Interface),简称为API函数.我们在编写Windows程序时所说的API函数,就是指系统提供的函数,所有主要的Windows函数都在Windows.h头文件中进行了说明. SDK的全称是Software Development Kit

ios程序后台运行设置(不是太懂)

文一 我从苹果文档中得知,一般的应用在进入后台的时候可以获取一定时间来运行相关任务,也就是说可以在后台运行一小段时间. 还有三种类型的可以运行在后以, 1.音乐 2.location 3.voip 文二 在IOS后台执行是本文要介绍的内容,大多数应用程序进入后台状态不久后转入暂停状态.在这种状态下,应用程序不执行任何代码,并有可能在任意时候从内存中删除.应用程序提供特定的服务,用户可以请求后台执行时间,以提供这些服务. 判断是否支持多线程 UIDevice* device = [UIDevice

[VC]在VC++中实现让程序只运行一个实例的方法且实现该实例

方法一: 有时候在开发应用程序时,希望控制程序运行唯一的实例.例如,最常用的mp3播放软 件Winamp,由于它需要独占计算机中的音频设备,因此该程序只允许自身运行唯一的一个例程.在Visual C++的开发实践中,对于16位的Windows系统,应用程序的hPrevInstance句柄保存了应用程序上一个运行的实例,可以用该值来检查是否 有实例运行:然而在32位Windows系统下,这个值总是NULL,所以无法利用该值来实现程序运行唯一实例.本实例给出了解决这个问题的简单办法,只 要将程序中稍