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
Solved

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

Posted on 2003-11-04
7
245 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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