Csharp/C#教程:C#判断某程序是否运行的方法分享

本文实例讲述了C#判断某程序是否运行的方法,分享给大家供大家参考。

具体实现方法如下:

[DllImport("user32.dll")] privatestaticexternbool SetForegroundWindow(IntPtrhWnd); [DllImport("user32.dll")] privatestaticexternboolShowWindowAsync(IntPtrhWnd,intnCmdShow); [DllImport("user32.dll")] privatestaticexternboolIsIconic(IntPtrhWnd); //消息函数 [DllImport("user32.dll",EntryPoint="PostMessageA")] publicstaticexternboolPostMessage(IntPtrhWnd,intMsg,intwParam,intlParam); [DllImport("user32.dll")] publicstaticexternIntPtrFindWindow(stringstrclassName,stringstrWindowName); [DllImportAttribute("user32.dll")] publicstaticexternintSendMessage(IntPtrhWnd,intMsg,intwParam,intlParam); publicconstintWM_SYSCOMMAND=0x0112; publicconstintSC_MAXIMIZE=0xF030; privatestringexeName="SaoMiaoApp"; publicvoidSetForm() { Process[]processes=Process.GetProcessesByName(exeName); if(processes.Length>0) { IntPtrhWnd=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"); } }

希望本文所述对大家的C#程序设计有所帮助。

您可能感兴趣的文章:让应用程序只运行一个实例的实现方法解决C#程序只允许运行一个实例的几种方法详解bat脚本实例实现只允许运行一个实例(安装程序、创建快捷方式脚本)C#确保只有一个实例在运行的方法C#运行时相互关系浅析C#编程中设置程序只可被运行一次的方法C#简单实现防止多个程序运行的方法C#如何防止程序多次运行的技巧C#WinForm判断程序是否已经在运行,且只允许运行一个实例,附源码

标签: 方法 程序 运行

C/C++实现贪吃蛇逐步运动效果

C语言中逻辑运算符与条件运算符的学习教程

上述就是C#学习教程:C#判断某程序是否运行的方法分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/905794.html

(0)
上一篇 2021年10月23日
下一篇 2021年10月23日

精彩推荐