正好我寫個(gè)一個(gè)函數(shù)封裝在DLL里了,代碼是這樣的:
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),興安企業(yè)網(wǎng)站建設(shè),興安品牌網(wǎng)站建設(shè),網(wǎng)站定制,興安網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,興安網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
''' summary
''' 檢查進(jìn)程是否運(yùn)行
''' /summary
''' param name="ProcessName"要檢查的進(jìn)程名/param
''' returns/returns
''' remarks/remarks
Public Function CheckProcessByName(ByVal ProcessName As String) As Boolean
Dim MgmtClass As New ManagementClass("Win32_Process")
Dim rtnVal As Boolean = False
Dim mo As New ManagementObject()
For Each mo In MgmtClass.GetInstances()
If mo("Name").ToString().ToLower() = ProcessName.ToLower() Then
rtnVal = True
End If
Next
Return rtnVal
End Function
知道PID的話:
''' summary
''' 返回所有窗口句柄
''' /summary
''' returns/returns
''' remarks/remarks
Public Function ListAllProcessesHandle() As String
Dim sb As New StringBuilder()
Dim p As New Process()
For Each p In Process.GetProcesses(".")
Try
If p.MainWindowTitle.Length 0 Then
sb.Append("句柄:" + p.MainWindowHandle.ToString() + Environment.NewLine)
End If
Catch
End Try
Next
Return sb.ToString()
End Function
窗口隱藏進(jìn)程總有吧,函數(shù)調(diào)用的參數(shù)是進(jìn)程名,不是窗口名。
函數(shù)是自己寫的沒有調(diào)用API
可以進(jìn)“任務(wù)管理器” 兩個(gè)步驟確定程序是否處于假死。 1,在“應(yīng)用程序”里面,是否能切換該程序,如果不行,可以假定程序死機(jī)。 2,在“進(jìn)程”中找到該程序,看CPU和內(nèi)存使用,的數(shù)據(jù)有沒有變化,如果20秒不變化,說明假死。
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Dim instance As Process = RunningInstance()
If instance IsNot Nothing Then
ShowWindowAsync(instance.MainWindowHandle, 3) '調(diào)用api函數(shù),正常顯示窗口
Return
End If
Dim F1 As New Form1
Application.Run(F1) '顯示窗體
End Sub
DllImport("User32.dll")
Public Function ShowWindowAsync(ByVal hWnd As System.IntPtr, ByVal cmdShow As Integer) As Boolean
End Function
Private Function RunningInstance() As Process '返回進(jìn)程中已經(jīng)打開的程序
Dim current As Process = Process.GetCurrentProcess()
Dim processes As Process() = Process.GetProcessesByName(current.ProcessName)
For Each process As Process In processes
If process.Id current.Id Then
If process.MainModule.FileName = current.MainModule.FileName Then
Return process
End If
End If
Next
Return Nothing
End Function
End Module
VB.net(VS2008)里面比C#還好弄,不需要自己加manifest,直接在項(xiàng)目屬性的“應(yīng)用程序”里面點(diǎn)擊“查看UAC設(shè)置”,在新打開的app.manifest里面把 requestedExecutionLevel level="asInvoker" uiAccess="false" / 替換成 requestedExecutionLevel level="requireAdministrator" uiAccess="false" / 再編譯就行了。
用process.GetProcesses()
或者process.GetProcessByid() 獲取進(jìn)程信息,
這個(gè)提供進(jìn)程即可以判斷程序是否已經(jīng)啟動(dòng)
這個(gè)是最一般的方法了
希望能幫到你