Service Handle

hi, I need to find out how to get the Service handle.

on forms, I use Application.handle, in units, I use form1.handle.

how can I show the handle of the service app?

Sal.
LVL 2
SaLzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geobulCommented:
Hi,

Service1.ServiceThread.Handle

is the handle of your service thread.

Regards, Geo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SaLzAuthor Commented:
ok, another problem, in a form, for the location of the exe, I normally put Application.ExeName to get the path and exe name,

how can I get this in a service?
0
vaceroseCommented:
This is a very inefficient function but it works.

function GetAppPath: String;
Var
  Test : String;
  Res  : Longint;
  CurSize : Longint;
begin
  CurSize := 1024;
  SetLength(Test, CurSize);
  Res := GetModuleFilename(GetModuleHandle(nil), PChar(test), CurSize);
  If (res > curSize) then
  begin
    CurSize := res + 10;
    SetLength(Test, CurSize);
    Res := GetModuleFilename(GetModuleHandle(nil), PChar(test), CurSize);
  end;
  Setlength(Test, Res);
  test := ExtractFilePath(Test);
  Result := test;
end;
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

geobulCommented:
TServiceApplication object doesn't have such property. I haven't tried that but there is such information (lpBinaryPathName) in QUERY_SERVICE_CONFIG structure defined in WinSvc unit. You have to:
- open the service manager using OpenSCManager,
- then open the service in interest using OpenService API (dwDesiredAccess = SERVICE_QUERY_CONFIG) which will return a handle for the next step,
- request that info using QueryServiceConfig API,
- get that element 'lpBinaryPathName' from the returned structure,
- and finally close both handles (service handle and SCManager handle).

Regards, Geo
0
geobulCommented:
If vacerose's code works then there is a short version:

function GetAppExeName: string;
var
  FN: array[0..MAX_PATH - 1] of char;
begin
  SetString(result, FN, GetModuleFileName(GetModuleHandle(nil), FN, SizeOf(FN)));
end;

Regards, Geo
0
TheRealLokiSenior DeveloperCommented:
I'm guessing just paramstr(0) doesn't work in a service then? That's how i get the current file's path and name
0
SaLzAuthor Commented:
lol, u know what, I totally forgot all about paramstr(0) for exe location, it works in services.
0
geobulCommented:
I also forgot about that :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.