Results 1 to 3 of 3

Thread: [RESOLVED] Question involving Inno Setup Script

  1. #1

    Thread Starter
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Resolved [RESOLVED] Question involving Inno Setup Script

    Hi all, I am new to scripting with Inno Setup. I've written a program that provides diagnostic services for another program. Chances are high that users who install this program already have the other program on their computers so I want the installer to check if the other program exists (I know how to do this using RegKeyExists), and if it does I want it to extract the location of that program which is stored in one of the values.

    My question is, can this be done? Does Inno Setup Script have a function for retrieving RegKeyValues?

    I guess it should look something like this:
    Code:
    #define MyAppDir := BaseDir()
    #define MyAppName 'test'
    
    [Setup]
    DefaultDirName={#MyAppDir}{#MyAppName}
    
    [Code:]
    function BaseDir(): String 
        var ParentProgInstalled : Boolean 
    begin 
        ParentProgInstalled := RegKeyExists(HKLM, 'thesubkeyname'); 
        if ParentProgInstalled =true then begin 
            Result := 'Insert appropriate function to retrieve regkeyvalue'; 
        end; 
        else begin 
            Result := 'C:\myprog\myprogfolder' 
        end; 
    end;
    Oh and there isn't actually a colon in my code tag, i just want it to parse correctly..

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Question involving Inno Setup Script

    ok, so you want this for your DefaultDirName line in the setup section

    [setup]
    DefaultDirName={code:GetInstallDirectory}

    Then in the code section:

    Code:
    [C0DE]
    function GetInstallDirectory(S: String) : String;
    var installDirectory : String;
    begin
      if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\SOMEKEY', 'somevalue', installDirectory) then
          //SUCCESS READING VALUE
          Result := installDirectory
      else
          //FAILED READING VALUE
          Result := ExpandConstant('{pf}\my program\my program folder');
    end;
    You don't need to use RegKeyExists, because just querying the value fails when it doesn't exist. So if you fail, you use your default. Notice the use of Expand Constant on {pf} which will convert it to their program files directory (can't always assume Windows is on C

    So I am sure you can tell, but the values you want to change here are:

    'SOFTWARE\SOMEKEY'
    'somevalue'
    'my program\my program folder'

    Think this should get you going.

  3. #3

    Thread Starter
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Question involving Inno Setup Script

    Thanks kleinma, this is fantastic. A really good glimpse into the power of Inno Setup.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width