Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > Run Program as process in NT4.0


Reply
 
Thread Tools Display Modes
  #1  
Old 05-21-2001, 02:19 PM
OberCanober
Guest
 
Posts: n/a
Default Run Program as process in NT4.0


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!






Reply With Quote
  #2  
Old 05-21-2001, 05:40 PM
bambi
Guest
 
Posts: n/a
Default Re: Run Program as process in NT4.0

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.



Reply With Quote
  #3  
Old 05-22-2001, 09:00 AM
OberCanober
Guest
 
Posts: n/a
Default Re: Run Program as process in NT4.0

?????
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.

Reply With Quote
  #4  
Old 05-22-2001, 12:27 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default Re: Run Program as process in NT4.0

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
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #5  
Old 05-22-2001, 01:08 PM
Derek Stone
Guest
 
Posts: n/a
Default Re: Run Program as process in NT4.0

<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
Reply With Quote
  #6  
Old 05-22-2001, 01:13 PM
Derek Stone
Guest
 
Posts: n/a
Default Re: Run Program as process in NT4.0

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
Reply With Quote
  #7  
Old 05-22-2001, 02:28 PM
OberCanober
Guest
 
Posts: n/a
Default Re: Run Program as process in NT4.0

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!

Reply With Quote
  #8  
Old 05-23-2001, 04:32 AM
Derek Stone
Guest
 
Posts: n/a
Default Re: Run Program as process in NT4.0

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->