Solved

NT Service

Posted on 2001-07-03
7
645 Views
Last Modified: 2008-03-17
I had written a small monitoring program for Windows 98 and have started to convert it into a service for NT.

So far it looks good, i've used a template from http://www.jgsoftware.com/nt.htm -> the vpcsrvce.zip and the service installs, accesses all my modules and functions from the form and everything is great...until... i use the FindWindow command.

For some reason it just wont work when being used as part of a service. It just seems to return 0 always.

If you download the zip file above and replace the timer procedure 'beep' command with...

var h:hwnd;
begin
  h:= Findwindow (nil,'Registry Editor');
  if h <> 0 then beep;
end;

what would work as a program, seems to not work in the service form. Any ways to get around this problem... do i have to change one of the lines of code in the service procedures included?

I have already tested the equivalent program on NT and it runs fine, but i need it to run as a service, and i would preferably keep the template above as it is easy apart from this one small problem.

Thanks for your help.
0
Comment
Question by:frangers99
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 6251251
Did you try to make it Interactive service, try to change Interactive to True.

Did you test FindWindow with these parameters and it returns non-zero number when Registry editor is working?
0
 

Author Comment

by:frangers99
ID: 6251510
How do i make it interactive if im using the template above, i only have Delphi 4 Standard which means i dont have the wizards etc... and yes, it didnt beep when i started regedit (inferring that h must have been 0)
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 300 total points
ID: 6251729
Edit uService.pas:

Add

  SERVICE_INTERACTIVE_PROCESS   = $00000100;

to the const section.


Change the line

    ServiceControlHandle := CreateService(SCManagerHandle ,PCHAR(FServiceName), PCHAR(FServiceDisplayName),
                            SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,
                            SERVICE_ERROR_NORMAL, Path, nil, nil, nil, nil, nil);

to

    ServiceControlHandle := CreateService(SCManagerHandle ,PCHAR(FServiceName), PCHAR(FServiceDisplayName),
                            SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS or SERVICE_INTERACTIVE_PROCESS, SERVICE_DEMAND_START,
                            SERVICE_ERROR_NORMAL, Path, nil, nil, nil, nil, nil);
0
Technology Partners: 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!

 

Author Comment

by:frangers99
ID: 6251948
Epsylon.
Thanks again, you always answer my questions so fast! That had me confused for quite a while.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6251981
:o)   Take a deep breath and breathe out s l o w l y .....

Thanks a lot for the points!
0
 

Author Comment

by:frangers99
ID: 6252488
just one last thing.... i get a little popup everynow and then while the service is running, telling me everything is fine.... being an invisible monitor, i dont wanna any popups, where are they being called from and how do i remove them.

thanks
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6262346
Sorry, it seems that I don't get any notifications anymore from question where my answer was accepted. A very serious bug in EE. I've reported to CS it but I don't get any response.

About your problem: look in uService. There are some writeln statement which my cause the popups.
0

Featured Post

Industry Leaders: 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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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