'Непонятно про что было сказанно ">этой самой запущенной программы", но тем не менее: 'Держи, выдрал из своей про-ги. Меняет приоритет для приложения по полному пути к EXE_шнику... 'в модуль: Option Explicit Public Const TH32CS_SNAPPROCESS As Long = 2& Public Const MAX_PATH As Integer = 260 Public 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 Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Public Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long Public Const IDLE_PRIORITY_CLASS = &H40 Public Const NORMAL_PRIORITY_CLASS = &H20 Public Const HIGH_PRIORITY_CLASS = &H80 Public Const REALTIME_PRIORITY_CLASS = &H100 Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Public Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long Public Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long Public Function PriorityApp(myName As String, mySPrior As Long) As Boolean Const PROCESS_ALL_ACCESS = 0 Dim uProcess As PROCESSENTRY32 Dim rProcessFound As Long Dim hSnapshot As Long Dim szExename As String Dim exitCode As Long Dim myProcess As Long Dim AppSet As Boolean Dim appCount As Integer Dim i As Integer appCount = 0 uProcess.dwSize = Len(uProcess) hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0& rProcessFound = ProcessFirst(hSnapshot, uProcess)
Do While rProcessFound i = InStr(1, uProcess.szExeFile, Chr(0)) szExename = LCase$(Left$(uProcess.szExeFile, i - 1)) If Right$(szExename, Len(myName)) = LCase$(myName) Then AppSet = True appCount = appCount + 1 myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID) AppSet = SetPriorityClass(myProcess, mySPrior) Exit Function End If rProcessFound = ProcessNext(hSnapshot, uProcess) Loop Call CloseHandle(hSnapshot) End Function 'в форму или куда хошь... 'ставит калькулятору реал-тайм (самый высокий) приоритет. Private Sub Command1_Click() Call PriorityApp("C:\Windows\calc.exe", REALTIME_PRIORITY_CLASS) End Sub
Ответить
|