正好我寫(xiě)個(gè)一個(gè)函數(shù)封裝在DLL里了,代碼是這樣的:
高淳網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)成立與2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專(zhuān)注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
''' 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的話(huà):
''' 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ù)是自己寫(xiě)的沒(méi)有調(diào)用API
''' summary
''' 返回某進(jìn)程PID
''' /summary
''' param name="ProcessName"進(jìn)程名(不帶后綴)/param
''' returns/returns
''' remarks/remarks
Public Function ProcessPidOnly(ByVal ProcessName As String) As String
Dim myProcess As Process() = Process.GetProcessesByName(ProcessName)
Dim pid As String = ""
If myProcess.Length - 1 = 0 Then
pid = myProcess(0).Id
Else
For i As Short = 0 To myProcess.Length - 1
pid = pid myProcess(i).Id ";"
Next
End If
Return pid
End Function
關(guān)于進(jìn)程的問(wèn)題你問(wèn)了多次吧,為何不多看看Process
Dim p As Process() = Process.GetProcessesByName("qq")
If p.Count = 1 Then
Dim p1 As Process = p(0)
Dim m = p1.Modules '進(jìn)程的所有模塊。
End If
Dim p As Process = Process.GetProcessById(Pid)‘通過(guò)pid取進(jìn)程。
使用wmi
類(lèi)“Win32_Processor”中LoadPercentage屬性為當(dāng)前的cpu使用率
示例代碼: Private Sub Timer1_Timer()
Dim WMI服務(wù) As Object
Dim 對(duì)象 As Object
Dim 子對(duì)象 As Object
Dim 電腦名 As String
Dim 刷新 As Long
刷新 = 0
電腦名 = "." '表示本地計(jì)算機(jī)
Set WMI服務(wù) = GetObject("winmgmts://" 電腦名 "/root/cimv2")
Set 對(duì)象 = WMI服務(wù).InstancesOf("Win32_Processor")
Me.CurrentX = 0
Me.CurrentY = 0
For Each 子對(duì)象 In 對(duì)象
If 刷新 = 0 Then
刷新 = 1
Me.Cls
End If
Me.Print 子對(duì)象.Name "[" 子對(duì)象.CurrentClockSpeed "Hz] 使用率:" _
子對(duì)象.LoadPercentage "%"
Next
End Sub