EaBIM

标题: 从AutoCAD2006开始引入了动态块这个概念,动态块的使用使得我们的图形更加灵活,可... [打印本页]

作者: 萧闫子    时间: 2014-1-8 14:05
标题: 从AutoCAD2006开始引入了动态块这个概念,动态块的使用使得我们的图形更加灵活,可...
  1. 网上找到得,判断某程序是否运行Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
  2. Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
  3. Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
  4. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  5. Private Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
  6. Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
  7. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  8. Private Const TH32CS_SNAPHEAPLIST = &H1
  9. Private Const TH32CS_SNAPPROCESS = &H2
  10. Private Const TH32CS_SNAPTHREAD = &H4
  11. Private Const TH32CS_SNAPMODULE = &H8
  12. Private Const TH32CS_SNAPALL = TH32CS_SNAPPROCESS + TH32CS_SNAPHEAPLIST + TH32CS_SNAPTHREAD + TH32CS_SNAPMODULE
  13. Private Const PROCESS_TERMINATE = 1
  14. Private Const PROCESS_QUERY_INFORMATION = 1024
  15. Private Const PROCESS_VM_READ = 16
  16. Private Const PROCESS_ALL_ACCESS = &H1F0FFF
  17. Private Const MAX_PATH = 260
  18. Private Type PROCESSENTRY32
  19.     dwsize As Long
  20.     cntusage As Long
  21.     th32ProcessID As Long
  22.     th32DefaultHeapID As Long
  23.     th32ModuleID As Long
  24.     cntThreads As Long
  25.     th32ParentProcessID As Long
  26.     pcPriClassBase As Long
  27.     dwFlags As Long
  28.     szExeFile As String * MAX_PATH
  29. End Type
  30. Public Function IsProcessRun(exeName As String) As Boolean
  31.     Dim snap As Long, ret As Long, lProcess As Long
  32.     Dim proc As PROCESSENTRY32
  33.     Dim mName As String * MAX_PATH, modName As String
  34.     snap = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0)
  35.     proc.dwsize = Len(proc)
  36.     ret = ProcessFirst(snap, proc)
  37.     Do While ret <> 0
  38.         mName = ""
  39.         Dim Modules(1 To MAX_PATH) As Long, cbMNeeded As Long
  40.         lProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, True, proc.th32ProcessID)
  41.         If lProcess <> 0 Then
  42.             ret = EnumProcessModules(lProcess, Modules(1), MAX_PATH, cbMNeeded)
  43.             If ret <> 0 Then ret = GetModuleFileNameExA(lProcess, Modules(1), mName, Len(mName))
  44.             modName = Trim(Left(mName, ret))
  45.             If InStr(LCase(modName), LCase(exeName)) Then
  46.                 CloseHandle snap
  47.                 IsProcessRun = True
  48.                 Exit Function
  49.             End If
  50.         End If
  51.         ret = ProcessNext(snap, proc)
  52.     Loop
  53.     CloseHandle snap
  54.     IsProcessRun = False
  55. End Function
  56. 使用的时候:Dim temp As Boolean
  57.                      temp = IsProcessRun("ACAD.exe")


复制代码





欢迎光临 EaBIM (https://eabim.net/) Powered by Discuz! X3.2