Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-04
7
Medium Priority
?
266 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
ID: 9680354
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
ID: 9680557
If you start the App from the Command Line then all you do is

/High ProgramPath
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9680599
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 48

Accepted Solution

by:
Mikal613 earned 1000 total points
ID: 9680622
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
ID: 9681020
Listening
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9681115
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
ID: 9681218
That does indeed work as advertised - tested under XP so far.  great job thanks!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

773 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