Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 program as a service

Status
Not open for further replies.

gust1480

Programmer
Mar 19, 2002
148
PH
does anyone knows how I could make may vb6 program behave like a service?! wherein no matter what windows login id is used or even if no windows user is login my program will still be running? Thanks.
 
You can add it to the list of services by adding an entry to the registry.
Then it runs like any of the other services when you start up.
I had a little prog that did it for you but I cant find it anymore.

Also using Regedit, if you put it in:-
HKEY_LOCAL_MACHINE/
SOFTWARE/
MICROSOFT/
WINDOWS/
RUN
I think it will run at startup for all users
 
>You can add it to the list of services by adding an entry to the registry
>Then it runs like any of the other services when you start up

No, it doesn't I'm afraid. I had a feeling that you might be labouring under this misapprehension.

Under W95/98/98SE/Me you used to be able to do this to get service-like behaviour (although those OSs never actually had genuine Services, just background tasks, albeit ones that could run without a user being logged in*). This was the RunServices key (HKLM\Software\Microsoft\Windows\CurrentVersion\ RunServices), which does not exist on the NT-based OSs. And just to make it clear, the 'Services' part of RunServices was a really a misnomer.

Under the NT-based OSs, closest you can get with a simple registry entry is the Run key that you mention. But this only runs the program when a user logs in (and, what's more, can only run it under the user's credentials) and terminates it when they log out. Again, this is nothing like a Service.



*Not that this was particularly important, since W9x didn't really have security and a user could also use the machine without logging in ...
 
Thanks.
Well how does one add it to "services" the way it is done by certain applications you install?
I had a prog that I though did it and put it in the bottom task bar but I cant find it anymore.
Maybe it simply added it to all the users in one go to make it look like a service?
 
>Well how does one add it to "services" the way it

I refer you to my first response in this thread
 
And just to make it clear, the 'Services' part of RunServices was a really a misnomer.

I think this is a little harsh, but it was true that a Win95 Service was not at all tghe same thing as an NT Service (a.k.a. Windows Service). There was really more to it than just the RunServices key, but not that much more. Most of it had to do with getting notified of logoff and shutdown, and housekeeping items of that nature.

A true Windows Service (NT) requires an extra thread for SCM communication. These can be provided through a parent process (srvany) or by using the ntsvc.ocx, or through more exotic means. Windows Services
 
>I think this is a little harsh

I'm afraid I have to disagree. The only difference between a program started via the RunServices (or RunServicesOnce) key and the Run (and RunOnce) key (and, indeed, a program started run by the user) was the point in the startup and login process at which the program would run.

 
Well it's hardly important to very many people today.

Surely you've heard of RegisterServiceProcess though, and for that matter the need to handle special window messages as briefly described in:
The application should provide for different users logging on at different times during its execution. The application can distinguish between a user logging off and the system shutting down by examining the lParam parameter of the WM_QUERYENDSESSION and WM_ENDSESSION messages. If the user shuts down the system, lParam is NULL. If the user logs off, lParam is set to ENDSESSION_LOGOFF.
A Win9x "service" linked for the Console Subsystem uses SetConsoleCtrlHandler to set a callback to get these notifications, since there is no window to receive messages for.

For that matter the RunServices key exists in both machine and user contexts:

These applications start before the user logs on. Specifically, the applications under HKEY_LOCAL_MACHINE are run before the desktop is created, and the applications under HKEY_CURRENT_USER are run after the desktop is created. In either case, the user is not yet validated, and the applications cannot assume that networking permissions are enabled. Until the user logs on, the application does not have access to network resources that the user has access to.
 
>Surely you've heard of RegisterServiceProcess
RegisterServiceProcess was a) not a requirement and b) could be run against any program you liked. I'm sorry, but that didn't make Calc or Notepad into services.

>the need to handle special window messages

No, there was no need to. It wasn't compulsory (despite the wording in some of Microsoft's documentation). It wasn't as if the 'service' wouldn't run if you didn't do it. And it wasn't as if the 'service' was treated any differently from any other programs by the OS in order to receive those messages. They were sent to all running programs.

Frankly, the naming of the keys should have been something like

RunEarlyCreateProcess
RunEarlyCreateProcessOnce

since that is all they actually did, and the API call:

TellThisProcessToIgnoreUserLogout


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top