任何人都可以帮助我使用 inno setup 示例脚本显示如何向 Windows 7 主机文件添加条目?

谢谢

最佳答案

lmhost 支持 #include 语句,因此您可以像这样包含自己的主机文件:

//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;

关于inno-setup - Inno setup 在windows 7下的hosts文件中添加一个条目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3473526/

10-14 01:13