Страница: 1 |
Страница: 1 |
Вопрос: Вопрос о приоритетах
Добавлено: 08.11.07 23:56
Автор вопроса: werber | Web-сайт:
Народ, помогите с одно штукой. Мне нужно, чтобы в проге можно было изменять её приоритет в Винде. Как это сделать?
Ответы
Всего ответов: 3
Номер ответа: 1
Автор ответа:
HACKER
Разработчик Offline Client
Вопросов: 236
Ответов: 8362
Профиль | | #1
Добавлено: 09.11.07 00:32
прырорытет указывается в CreateProcess, або когда прога уже запущена, открываешь процесс с флажком PROCESS_ALL_ACCESS (гы если админ в винде) и ставищ прыроритет с помощью апы SetPriorityClass вот такие дела Короче проси готовый код и прикладывай 20 wmz - всё сделаю
Номер ответа: 2
Автор ответа:
Mr.Smile
ICQ: 427682013
Вопросов: 14
Ответов: 464
Профиль | | #2
Добавлено: 09.11.07 02:15
Если только в твоей проге, то это должно помочь
Const THREAD_BASE_PRIORITY_LOWRT = 15
Const THREAD_BASE_PRIORITY_MIN = -2
Const THREAD_BASE_PRIORITY_MAX = 2
Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN
Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX
Const THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)
Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)
Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE
Const THREAD_PRIORITY_NORMAL = 0
Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT
Const HIGH_PRIORITY_CLASS = &H80
Const IDLE_PRIORITY_CLASS = &H40
Const NORMAL_PRIORITY_CLASS = &H20
Const REALTIME_PRIORITY_CLASS = &H100
Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
Private Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As Long
Private Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As Long
Private Declare Function GetCurrentThread Lib "kernel32" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim hThread As Long, hProcess As Long
'retrieve the current thread and process
hThread = GetCurrentThread
hProcess = GetCurrentProcess
'set the new thread priority to "lowest"
SetThreadPriority hThread, THREAD_PRIORITY_LOWEST
'set the new priority class to "idle"
SetPriorityClass hProcess, IDLE_PRIORITY_CLASS
'print some results
Me.AutoRedraw = True
Me.Print "Current Thread Priority:" + Str$(GetThreadPriority(hThread))
Me.Print "Current Priority Class:" + Str$(GetPriorityClass(hProcess))
End Sub
Номер ответа: 3
Автор ответа:
Mr.Smile
ICQ: 427682013
Вопросов: 14
Ответов: 464
Профиль | | #3
Добавлено: 11.11.07 02:09
Вот примерно то, о чем говорил HACKER:
' ProcessPriorityApiFunctions.bas
'
' Purpose:
' Contains all the API functions and functions used
' to set the applications process priority.
'********************************************************************
' Win32 API declarations for priority declaration
Private Declare Function _
GetWindowThreadProcessId Lib "user32" ( _
ByVal hWnd As Long, lpdwProcessId 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 Function SetPriorityClass Lib _
"kernel32" (ByVal hProcess As Long, _
ByVal dwPriorityClass As Long) As Long
Private Declare Function GetPriorityClass Lib _
"kernel32" (ByVal hProcess As Long) As Long
Private Declare Function CloseHandle Lib _
"kernel32" (ByVal hObject As Long) As Long
' Used by the OpenProcess API call
Private Const PROCESS_QUERY_INFORMATION _
As Long = &H400
Private Const PROCESS_SET_INFORMATION _
As Long = &H200
' Used by SetPriorityClass
Private Const NORMAL_PRIORITY_CLASS = &H20
Private Const IDLE_PRIORITY_CLASS = &H40
Private Const HIGH_PRIORITY_CLASS = &H80
Private Const REALTIME_PRIORITY_CLASS = &H100
Public Enum ProcessPriorities
ppIdle = IDLE_PRIORITY_CLASS
ppNormal = NORMAL_PRIORITY_CLASS
ppHigh = HIGH_PRIORITY_CLASS
ppRealtime = REALTIME_PRIORITY_CLASS
End Enum
Public Function GetProcessPriority(Optional _
ByVal ProcessID As Long, Optional ByVal hWnd _
As Long) As Long
'****************************************************************************
'GetProcessPriority
'
'Purpose: Gets the process priority of the application
'
'Input: ProcessID
' hWnd
'
'Output: Process Priority as a long
'****************************************************************************
Dim hProc As Long
Const fdwAccess As Long = _
PROCESS_QUERY_INFORMATION
' If not passed a PID, then find value from hWnd.
If ProcessID = 0 Then
Call GetWindowThreadProcessId(hWnd, _
ProcessID)
End If
' Need to open process with simple query
' rights, get the current setting, and close
' handle.
hProc = OpenProcess(fdwAccess, 0&, ProcessID)
GetProcessPriority = GetPriorityClass(hProc)
Call CloseHandle(hProc)
End Function
Public Function SetProcessPriority(Optional _
ByVal ProcessID As Long, Optional ByVal hWnd _
As Long, Optional ByVal Priority As _
ProcessPriorities = NORMAL_PRIORITY_CLASS) _
As Long
'****************************************************************************
'SetProcessPriority
'
'Purpose: Sets the process priority of the application
'
'Input: ProcessID
' hWnd
'
'Output: Process Priority as a long
'****************************************************************************
Dim hProc As Long
Const fdwAccess1 As Long = _
PROCESS_QUERY_INFORMATION Or _
PROCESS_SET_INFORMATION
Const fdwAccess2 As Long = _
PROCESS_QUERY_INFORMATION
' If not passed a PID, then find value from hWnd.
If ProcessID = 0 Then
Call GetWindowThreadProcessId(hWnd, _
ProcessID)
End If
' Need to open process with setinfo rights.
hProc = OpenProcess(fdwAccess1, 0&, ProcessID)
If hProc Then
' Attempt to set new priority.
Call SetPriorityClass(hProc, Priority)
Else
' Weren't allowed to setinfo, so just open
' to enable return of current priority setting.
hProc = OpenProcess(fdwAccess2, 0&, _
ProcessID)
End If
' Get current/new setting.
SetProcessPriority = GetPriorityClass(hProc)
' Clean up.
Call CloseHandle(hProc)
End Function
-------------------
* Process Explorer - намного улучшенный вариант Диспетчера задач Windows
[!] У Process Explorer'а своя система счисления приоритетов процессов. Например, вышеуказанный код выдает приоритет 32 (&H20), у Process Explorer'а это 8.
[!] Приведенный выше код округляет приоритеты процессов. Например, у процесса приоритет 9 (по СС Process Explorer'а), вышеуказанный код округляет приоритет до 8 (32, он же &H20).
[?] Кто-нибудь знает как узнать точный приоритет процесса?
[?] Как Process Explorer определяет приоритет процессов?