Solved

Code to get a VB executable alter its own priority to Above Normal or High

Posted on 2003-11-04
7
242 Views
Last Modified: 2010-05-01
rather than running at normal which is the default for all apps I would like the app to be able to alter its own priority to run faster as might be useful under user control..
0
Comment
Question by:Informative
  • 4
  • 2
7 Comments
 
LVL 3

Author Comment

by:Informative
Comment Utility
Oh the OS should work ideally under several OS environments ME/NT/XP/2000/2003 but if I had to choose one or two XP and 2003 would be best.
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
If you start the App from the Command Line then all you do is

/High ProgramPath
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
Const THREAD_BASE_PRIORITY_IDLE = -15Const THREAD_BASE_PRIORITY_LOWRT = 15Const THREAD_BASE_PRIORITY_MIN = -2Const THREAD_BASE_PRIORITY_MAX = 2Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MINConst THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAXConst THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLEConst THREAD_PRIORITY_NORMAL = 0Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRTConst HIGH_PRIORITY_CLASS = &H80Const IDLE_PRIORITY_CLASS = &H40Const NORMAL_PRIORITY_CLASS = &H20Const REALTIME_PRIORITY_CLASS = &H100Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As LongPrivate Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As LongPrivate Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As LongPrivate Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As LongPrivate Declare Function GetCurrentThread Lib "kernel32" () As LongPrivate Declare Function GetCurrentProcess Lib "kernel32" () As LongPrivate 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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 48

Accepted Solution

by:
Mikal613 earned 250 total points
Comment Utility
Const THREAD_BASE_PRIORITY_IDLE = -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()  
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
0
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
Listening
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
Private Sub Form_Load()  
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_HIGHEST 'set the new priority class to "idle"  
 SetPriorityClass hProcess,HIGH_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
0
 
LVL 3

Author Comment

by:Informative
Comment Utility
That does indeed work as advertised - tested under XP so far.  great job thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now