Solved

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

Posted on 2003-11-04
7
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 48

Accepted Solution

by:
Mikal613 earned 250 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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
Course of the Month11 days, 9 hours left to enroll

623 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