OberCanober
05-21-2001, 02:19 PM
Anyone know the API for these NT Functions?
Run a my program as a process in NT 4.0.
Change the priority of my program in NT 4.0 to realtime.
Help me please!
bambi
05-21-2001, 05:40 PM
You can use the 'start' command to do this.
type start /? in a cmd
But you do not want to run your app realtime.
It _will_ stop your system.
And your app will not run much faster.
OberCanober
05-22-2001, 09:00 AM
?????
Not really sure how to do the start /?...
can you please give more of an example.
We are going to be running a application that runs in the back ground and watches a certain screen telling the user that they have completed an Item. This will keep a tally for them on a SQL server so the supervisor can see how much work they have done realtime instead of waiting to look at the inventory. I wanted it to run realtime to be sure it is running even if the computer is busy. I don't want them flying by the "Transaction Complete" screen without my program seeing it.
Thanks again for all your help.
BillSoo
05-22-2001, 12:27 PM
I actually sent a question like this to Dr. GUI. He published it and I got a MS teeshirt out of the deal....
Here is the excerpt from Ask Dr.GUI #46:
Trouble Sticking with My Priorities
Dear Dr. GUI,
We have a number of small communications programs written in VB3 that work well on Win3.1 and Win95 systems but fail on WinNT. We found that we could fix the problem by setting the priority of NTVDM.EXE to "High" from "Normal." The problem is that this setting doesn't stick. Every time we reboot NT we have to reset the priority. Is there a way to tell NT to store this priority as default? Failing that, is there a way to programmatically change the priority setting? We tried the Start command but it didn't seem to work.
Thanks,
Bill Soo
Dr. GUI replies:
As hard as Dr. GUI tries, he still gets these psychology questions. Oh, wait—this one is about operating system priorities, not personal priorities. Well, okay. Here goes:
There is no way to set a default priority level for an application. However, as you guessed, this can be done programmatically. It is a matter of calling SetPriorityClass and passing HIGH_PRIORITY_CLASS in the second parameter. The more difficult problem is getting the first parameter, which is the handle to the ntvdm.exe process. On Windows NT, the Process Status APIs (PSAPI) can be used to enumerate processes running on the system. The following steps can be used to find the ntvdm.exe process.
Call EnumProcesses. This PSAPI function returns an array of process IDs in the system.
The third parameter returned is the number of bytes returned. Divide this number by sizeof(DWORD) to get the number of processes running.
For each process ID:
Call OpenProcess to get a handle to the process.
If this succeeds, call EnumProcessModules to get an array of module handles (needed for next step).
Call GetModuleBaseName, passing the handle to the process and the first module handle. This gives you the name of the process.
Compare this to ntvdm.exe. If the comparison succeeds, call SetPriorityClass with the process handle.
If not, close the handle and go back to Step 1.
Note There may be more than one ntvdm.exe. The preceding steps will affect all of them.
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Derek Stone
05-22-2001, 01:08 PM
<pre><font color=green>'Some API functions you'll need to use</font color=green>
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
<font color=green>'Some constants you'll need to use</font color=green>
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
</pre>
If you need help using them wirte back.
Good Luck
-cl
http://vb.wsoftware.net
Derek Stone
05-22-2001, 01:13 PM
And what do you mean by "run my program as a process"?
A program is a process. Nomatter how you run it.
Do you mean run your program as a service?
If so visit these two webpages:
http://vbwire.com/advanced/howto/service.asp
http://vbwire.com/advanced/howto/service2.asp
Good Luck
-cl
http://vb.wsoftware.net
OberCanober
05-22-2001, 02:28 PM
Well by a process in NT all I really mean it only shows up when you ctrl-Alt-Del in the processes and not the applications. This is so that they will be less likely to close it. I don't know why they would close it but you know they will.
Thanks you crazed-lunatic for the links its exacly what I was looking for. HE HE
And thanks everyone for the help with the priority.
You really helped me out!
Derek Stone
05-23-2001, 04:32 AM
The only apps that show up in the task manager application tab are those who have windows presently open and running.
Just to clarify.
Good Luck
-cl
http://vb.wsoftware.net