C#判斷某程序是否運(yùn)行的方法
更新時(shí)間:2014年09月29日 11:05:33 投稿:shichen2014
這篇文章主要介紹了C#判斷某程序是否運(yùn)行的方法,代碼結(jié)構(gòu)簡(jiǎn)單功能實(shí)用,需要的朋友可以參考下
本文實(shí)例講述了C#判斷某程序是否運(yùn)行的方法,分享給大家供大家參考。
具體實(shí)現(xiàn)方法如下:
[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); // 消息函數(shù) [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標(biāo)志,表示還原窗體 //SendMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0); SetForegroundWindow(hWnd); } else { Process.Start(exeName + ".exe"); } }
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#多線程學(xué)習(xí)之(四)使用線程池進(jìn)行多線程的自動(dòng)管理
這篇文章主要介紹了C#多線程學(xué)習(xí)之使用線程池進(jìn)行多線程的自動(dòng)管理,實(shí)例分析了C#中線程池的概念與相關(guān)的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04使用C#實(shí)現(xiàn)簡(jiǎn)單的線性回歸的代碼詳解
最近注意到了NumSharp,想學(xué)習(xí)一下,最好的學(xué)習(xí)方式就是去實(shí)踐,因此從github上找了一個(gè)用python實(shí)現(xiàn)的簡(jiǎn)單線性回歸代碼,然后基于NumSharp用C#進(jìn)行了改寫,需要的朋友可以參考下2024-01-01c# 解決IIS寫Excel的權(quán)限問(wèn)題
使用以上方法必須對(duì)dcom進(jìn)行配置,給用戶使用office的權(quán)限2012-10-10C#中判斷、驗(yàn)證字符串是否為日期格式的實(shí)現(xiàn)代碼
這篇文章主要介紹了C#中判斷、驗(yàn)證字符串是否為日期格式的實(shí)現(xiàn)代碼,使用DateTime類中自帶的兩個(gè)方法實(shí)現(xiàn),需要的朋友可以參考下2014-08-08C#實(shí)現(xiàn)類似jQuery的方法連綴功能
這篇文章主要介紹了C#實(shí)現(xiàn)類似jQuery的方法連綴功能,可以簡(jiǎn)化語(yǔ)句,使代碼變得清晰簡(jiǎn)單,感興趣的小伙伴們可以參考一下2015-11-11