系统粉 > 电脑问答 > 其他问答

已解决帮帮手精简一下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
相关问答
最新其他问答
解决方法