當前位置:係統粉 > 電腦問答 > 其他問答 > 幫幫手精簡一下VB代碼

幫幫手精簡一下VB代碼

提問者:_某a君_  |  瀏覽 次  |  提問時間:2017-03-10  |  回答數量:2

幫幫手精簡一下VB代碼 Option ExplicitPrivate Declare Function CreateToolhelp32Snapshot Lib \"kernel32\" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As LongPrivate Declare Function Process32First Lib \"kernel32\" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As LongPrivate Declare Function Process32Next Lib \"kernel32\" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As LongPrivate Declare Function TerminateProcess Lib \"kernel32\" (ByVal hProcess As Long, ByVal uExitCode As Long) As LongPrivate Declar

已有2條答案
暴力的羅傑

暴力的羅傑

回答數:177  |  被采納數:59

2017-03-10 19:43:39
Option Explicit
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long
Private Const TH32CS_SNAPPROCESS = &H2&
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
aaa As String * 24
szExeFile As String * 260
End Type
Function GetPsPid(sProcess As String) As Long
Dim lSnapShot As Long
Dim lNextProcess As Long
Dim tPE As PROCESSENTRY32
lSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
tPE.dwSize = Len(tPE)
lNextProcess = Process32First(lSnapShot, tPE)
Do While lNextProcess
If LCase$(sProcess) = LCase$(Left(tPE.szExeFile, InStr(1, tPE.szExeFile, Chr(0)) - 1)) Then
GetPsPid = tPE.th32ProcessID
Exit Function
End If
lNextProcess = Process32Next(lSnapShot, tPE)
Loop
End Function
Private Sub Command1_Click()
Print GetPsPid(Text1.Text)
End Sub
讚 17
鳴人的性格

鳴人的性格

回答數:16  |  被采納數:1

2017-03-10 19:27:17
謝謝了...
讚 1
解決方法
  • 微軟推出簡曆助理 聯手LinkedIn幫用戶完善簡曆

    微軟推出簡曆助理 聯手LinkedIn幫用戶完善簡曆

    北京時間11月9日早間消息,微軟今天推出一款產品,讓更新簡曆變得更容易。簡曆助理(Resume Assistant)是微軟Word中的一項新功能,可利用LinkedIn數據,幫助O...

  • 忘記windows xp係統密碼?高手幫你輕鬆解決

    忘記windows xp係統密碼?高手幫你輕鬆解決

      Windows XP是一個比較安全的操作係統,每次啟動時都要求選擇賬戶並輸入密碼,那麼如果忘記係統密碼了,?而且在安裝時也沒有做相應的應急盤,怎麼辦呢?於是小編經過多...

  • 不會寫簡曆?微軟將領英整合到Word幫你

    不會寫簡曆?微軟將領英整合到Word幫你

    在去年微軟花費了262億美元巨資收購了領英(LinkedIn),創了微軟收購史上最高價,到了今年6月微軟將領英整合到Windows 10當中。花費了如此巨資自然不會隻有係統內置軟件...

  • 還在費心學編程? 微軟用深度學習 AI 幫你寫代碼

    還在費心學編程? 微軟用深度學習 AI 幫你寫代碼

    在過去的幾十年中,無論在硬件組織還是軟件架構上,計算機行業已經發生了翻天覆地的變化,各種軟硬件產品的性能和用戶體驗均得到了顯著提升。但對程序員而言,軟件編碼的本質似乎並沒有什麼本質...

版權信息

Copyright @ 2011 係統粉 版權聲明 最新發布內容 網站導航