Solved

NT Service

Posted on 2001-07-03
7
646 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
[X]
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
  • 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
Independent Software Vendors: 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

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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