Solved

NT Service

Posted on 2001-07-03
7
640 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:frangers99
Comment Utility
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
Comment Utility
: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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now