> Кусок кода: закрыть приложение "FSTSCALE.EXE", если оно открыто. Вот: Option Explicit Const TH32CS_SNAPHEAPLIST = &H1 Const TH32CS_SNAPPROCESS = &H2 Const TH32CS_SNAPTHREAD = &H4 Const TH32CS_SNAPMODULE = &H8 Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE) Const MAX_PATH As Integer = 260 Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Public Function Close_Process(ByVal Str_Process As String) As Long Dim Lng_Snap As Long, Lng_Ret As Long, Process As PROCESSENTRY32 Lng_Snap = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0) Process.dwSize = Len(Process) Lng_Ret = Process32First(Lng_Snap, Process) Do While Lng_Ret If Right(Left(Process.szExeFile, InStr(1, Process.szExeFile, Chr(0)) - 1), Len(Str_Process)) = Str_Process Then TerminateProcess OpenProcess(0, True, Process.th32ProcessID), 0 Lng_Ret = Process32Next(Lng_Snap, Process) Loop CloseHandle Lng_Snap End Function
Private Sub Form_Load() ' Вместо Winamp мона вставить любое имя Call Close_Process("WINAMP.EXE") End Sub |