係統粉 > 電腦問答 > 其他問答

已解決幫幫手精簡一下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

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
2017-03-10 19:43:39
讚 17
鳴人的性格

鳴人的性格

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

謝謝了...
2017-03-10 19:27:17
讚 1
相關問答
最新其他問答
解決方法