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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract path from TService 2

Status
Not open for further replies.

Nordlund

Programmer
Jul 17, 2001
458
SE
Hi all.
How do I extract the path from a TService like the Application objects Exename function.???





//Nordlund
 
Hi,

you can find your service path at follow location in registry :
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<your service.name>

I keep service my installation path under a registry value 'InstallDir' after service installation. Here's an example :


Code:
procedure Tsvc_dSMS.ServiceAfterInstall(Sender: TService);

const STR_REGKEY_SVC = '\SYSTEM\CurrentControlSet\Services\svc_dSMS';

var Reg        : TRegistry;
    ImagePath  : string;

begin
// create needed registry entries after service installation
 try
  Reg:=TRegistry.Create;
  Reg.RootKey:=HKEY_LOCAL_MACHINE;
  // set service description
  if Reg.OpenKey(STR_REGKEY_SVC,False) then
   begin
    ImagePath:=Reg.ReadString(STR_REGVAL_IMAGEPATH);
    Reg.WriteString(STR_REGVAL_DESCRIPTION,STR_INFO_SVC_DESC);
    Reg.CloseKey;
   end;
  // set message resource for eventlog
  if Reg.OpenKey(STR_REGKEY_EVENTMSG,True) then
   begin
    Reg.WriteString(STR_REGVAL_EVENTMESSAGEFILE,ImagePath);
    Reg.WriteInteger(STR_REGVAL_TYPESSUPPORTED,7);
    Reg.CloseKey;
   end;
  // set installdir 
  if ImagePath <> '' then
   if Reg.OpenKey(STR_REGKEY_FULL,True) then
    begin
     Reg.WriteString(STR_REGVAL_INSTALLDIR,ExtractFilePath(ImagePath));
     Reg.CloseKey;
    end;
   FreeAndNil(Reg);
 except
  if Assigned(Reg) then FreeAndNil(Reg);
 end;
end;

Greetings,


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top