Board index » delphi » Registry-Newbie - Accessing it, and using it instead of WIN.INI

Registry-Newbie - Accessing it, and using it instead of WIN.INI

Hi,
Two simple question that I haven't found an answer to yet.
(I've tried the 'Win32'-help, but I can't figure out the parameters)

* I have managed to insert the working path of my program by
  adding the key: HKEY_CURRENT_USER\Software\MyTinyApp\StartUp
  with the value WorkPath='c:\Program Files\MyTinyApp\' with the help
  of InstallShield Delphi 2.0 Edition.
  But how can I access this information from my application?

  Basically I want something like this in the FormCreate section:
  WorkingPath:=(some code who read's the path from the registry :)
  Anyone who knows exactly what I have to write?

* In WIN.INI, I used 'run=c:\MyTinyApp\Tiny.Exe' when I wanted
  the program to execute at startup of windows.
  Anyone who knows how to do this in the registry? Preferable in
  the setup (with InstallShield)

Thanks in advance!

..torje..
(who bought a Delphi 2 book with 938 pages where the word 'Registry'
 is mentioned once :)

 

Re:Registry-Newbie - Accessing it, and using it instead of WIN.INI


Quote
Torje R?rvik wrote:

> Hi,
> Two simple question that I haven't found an answer to yet.
> (I've tried the 'Win32'-help, but I can't figure out the parameters)

> * I have managed to insert the working path of my program by
>   adding the key: HKEY_CURRENT_USER\Software\MyTinyApp\StartUp
>   with the value WorkPath='c:\Program Files\MyTinyApp\' with the help
>   of InstallShield Delphi 2.0 Edition.
>   But how can I access this information from my application?

>   Basically I want something like this in the FormCreate section:
>   WorkingPath:=(some code who read's the path from the registry :)
>   Anyone who knows exactly what I have to write?

> * In WIN.INI, I used 'run=c:\MyTinyApp\Tiny.Exe' when I wanted
>   the program to execute at startup of windows.
>   Anyone who knows how to do this in the registry? Preferable in
>   the setup (with InstallShield)

> Thanks in advance!

> ..torje..
> (who bought a Delphi 2 book with 938 pages where the word 'Registry'
>  is mentioned once :)

Check out the TRegIniFile object.  It handles obtaining or placing
information in the regestry.  It is well documented in the VCL Help, but
make sure you have the new copy.  It is avalabel from Borland at their
web site.

Mike

Re:Registry-Newbie - Accessing it, and using it instead of WIN.INI


Quote
In article <3217CA17.4...@netins.net> Michael Henderson <hend...@netins.net> writes:
> It is well documented in the VCL Help, but
>make sure you have the new copy.  It is avalabel from Borland at their
>web site.

8-/  Didn't they do the same thing last time?  :-}

Yo, Borland!  If the documentation people aren't through yet, then the product
is NOT READY TO SHIP!  Give 'em all the time and resources they need, because
documentation has historically been your Achilles heel and I'm beginning to
see why.

Forcing me to download an umpty-megabyte file from your ftp-site is just not
my cup of tea.

Re:Registry-Newbie - Accessing it, and using it instead of WIN.INI


Torje R?rvik <to...@sn.no> wrote in article <320F09E3.6...@sn.no>...

Quote
> * I have managed to insert the working path of my program by
>   adding the key: HKEY_CURRENT_USER\Software\MyTinyApp\StartUp
>   with the value WorkPath='c:\Program Files\MyTinyApp\' with the help
>   of InstallShield Delphi 2.0 Edition.
>   But how can I access this information from my application?

uses
   Registry;

var
   TheReg: TRegistry;
   KeyName: String;
   ValueStr: String;

begin
   TheReg := TRegistry.Create;
   try
      TheReg.RootKey := HKEY_CURRENT_USER;
      KeyName := 'Software\MyTinyApp\StartUp;
      if TheReg.OpenKey(KeyName, False) then
      begin
         ValueStr := TheReg.ReadString('WorkPath');
         TheReg.CloseKey;
      end;
   finally
      TheReg.Free;
   end;
end;

Also note, the correct place to store the path to your application's EXE under
the Win95 registry is in:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App
Paths\MYAPP.EXE

Store the complete path to your app as the default value under that key.
Regstr.pas defines a constant for this path up through ...\App Paths\ as
REGSTR_PATH_APPPATHS.

Storing the path to your application's EXE here will allow a user to simply
type MYAPP (or whatever its name is) in Start|Run on the taskbar and your
application will launch.  Here's an example of how to create it:

uses
   Registry, Regstr;

var
   TheReg: TRegistry;
   KeyName: String;

begin
   TheReg := TRegistry.Create;
   try
      {Check AppPath setting, update if necessary}
      TheReg.RootKey := HKEY_LOCAL_MACHINE;
      KeyName := REGSTR_PATH_APPPATHS + ExtractFileName(Application.ExeName);
      if TheReg.OpenKey(KeyName, True) then
      begin
         if CompareText(TheReg.ReadString(''), Application.ExeName) <> 0 then
            TheReg.WriteString('', Application.ExeName);
         TheReg.CloseKey;
      end;
   finally
      TheReg.Free;
   end;
end;

Mark

Other Threads