user419118
user419118

Reputation: 41

Inno setup to add an entry in hosts file under windows 7

Can anyone help me with a inno setup sample script showing how to add an entry to windows 7 hosts file?

Thanks

Upvotes: 4

Views: 3046

Answers (2)

Jim In Texas
Jim In Texas

Reputation: 1535

lmhost supports #include statements, so you can include your own hosts file like this:

//call after inno setup step change
procedure UpdateLMhosts(CurStep: TSetupStep);
        var

            contents: TStringList;
            filename, statement: String;
            i: Integer;

        begin
            if(CurStep=ssDone) then begin
                filename := ExpandConstant('{sys}\drivers\etc\lmhosts');
                Log('Reading ' + filename);
                contents := TStringList.Create();
                if(FileExists(filename)) then begin
                    contents.LoadFromFile(filename);
                end;

                    //copy my lmhosts to the system's lmhosts
                statement := ExpandConstant('#INCLUDE {commonappdata}\MyBrand\MyApp\lmhosts');
                if(contents.IndexOf(statement) < 0) then begin
                    Log('Adding' + statement);
                    contents.Append(statement);
                    contents.SaveToFile(filename);
                end;
            end;
        end;

Upvotes: 4

Bernard
Bernard

Reputation: 7961

This seems like a task outside of the scope of what Inno Setup provides.

See the following Knowledge Base article for suggestions: http://www.jrsoftware.org/iskb.php?custom

Upvotes: 2

Related Questions