开发者

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

开发者 https://www.devze.com 2023-01-11 15:06 出处:网络
Can anyone help me with a inno setup sample script showing how to add an e开发者_如何学Cntry to windows 7 hosts file?

Can anyone help me with a inno setup sample script showing how to add an e开发者_如何学Cntry to windows 7 hosts file?

Thanks


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;


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号