How do I modify the HOSTS file? - Advanced Installer Community
stecy
Posts: 9
Joined: Wed Aug 29, 2012 3:22 pm

How do I modify the HOSTS file?

I need the installer to modify the HOSTS file and add a line to it and can't figure how to do it?

Also, is there a way to verify if the line is already present in the file and update the file only when needed?

Thanks.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How do I modify the HOSTS file?

Hello,

I'm afraid we don't have predefined support for this. However, in order to achieve what you want you can create your own custom action which will search in the related file and will set accordingly an installer property (e.g. set MY_PROP property with "true" if the line exists and with "false" otherwise).

Here are the steps to proceed:
- Go to "Custom Actions" page and add your search custom action after "Install Execution Stage -> Searches" action group.
- Go to "Files and Folders" page and add new text file update (i.e. YourFile.txt) using the [New Text File Update] toolbar button. In the "Edit Text File Update Dialog" select the "Append/Create Operation" and add your text line.
- Go to "Table Editor" page, select the "InstallExecuteSequence" table and set the "Condition" field, of the "AI_TxtUpdaterInstall" row, like this:
  • MY_PROP
- Build and run your project.

Also, please keep in mind that in order to achieve what you want you need an "Enterprise" or above license.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Hans.Z
Posts: 1
Joined: Wed Jun 05, 2013 9:35 pm

Re: How do I modify the HOSTS file?

Hello,
I need to do the same thing C:\Windows\System32\Drivers\etc\services :
Anyone please can explain more step by step, I'm using AI 9.9.
Thanks.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How do I modify the HOSTS file?

Hello and welcome to Advanced Installer forums,

Thank you for your interest in Advanced Installer.

I'm afraid I don't fully understand your scenario. Can you please give us more details about your scenario (maybe exemplify)?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Amanzhol
Posts: 5
Joined: Fri Jul 18, 2014 4:49 am

Re: How do I modify the HOSTS file?

Hello.
I also use Advanced Installer 11.3 but can't grasp from your explanations how to append lines to hosts file.
Please, could you give in detail step by step instructions how to do it.
If need be, i can send my .aip file.
Thanks.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How do I modify the HOSTS file?

Hello and welcome to Advanced Installer forums,

Thank you for your interest in Advanced Installer.

Here are a detailed steps list:
1. go to "Files and Folders" page and select the "Windows Volume -> Windows -> System" folder
2. under "System" folder create "drivers\etc" subfolders
3. select the "etc" folder and use the [New Text File Update] toolbar button to add a new text file update
4. in the "Include" field type hosts
5. remove the "Replace" operation and configure the "Append/Create" operation as you need
6. build and run your project

Also, for your reference please take a look on "Folder Paths" and "Package Types" articles.

If you have any question let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Amanzhol
Posts: 5
Joined: Fri Jul 18, 2014 4:49 am

Re: How do I modify the HOSTS file?

Thanks a lot Daniel!
There is one problem, my OS is 64-bit win 8 and in spite of i do it on System or System 64 folders and even create\add custom System32 folder, a result is one, hosts file is created/overwritten only in SysWOW64\drivers\etc folder. Maybe it depends on system permissions or anything else, but i've checked "Run as administrator" checkbox.
Please, could you help me resolve this issue, that hosts file is changed only in Windows\System32\drivers\etc.
Best regards.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How do I modify the HOSTS file?

Hello,

First of all I apologize for my delayed reply.

On a 64-bit machine, in order to update the HOSTS file in "System32" folder you should proceed like this:
- go to "Install Parameters" page and set the "Package Type" to a 64-bit package
- go to "Files and Folders" page and add the text file update under "Windows Volume\System64\..." folder
- rebuild and test again the package

If you have any question let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Amanzhol
Posts: 5
Joined: Fri Jul 18, 2014 4:49 am

Re: How do I modify the HOSTS file?

Thanks Daniel!
I've already fixed it myself )
One more question: Could I perform file move operation after file removal during uninstall.
Because I set file removal on removing all files that begins on hosts*, then set file move on moving bk-hosts to hosts in same ../driver/etc folder, but problem is always performs file move then file removal, so renamed hosts file is also deleted.
Is it possible to validate ip address in the edit box ?
I've already tried to do it with custom js script, but got no results.
Script example:

Code: Select all

var check_sip = Session.Property("CHECK_SERVER_IP_FLAG");

function ValidateIPaddress(ipaddress)   
{  
 if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))  
  {  
    return true;  
  }
 
return false;  
}  

var sip = Session.Property("SERVER_IP");

check_sip = ValidateIPaddress(sip);

Best regards.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How do I modify the HOSTS file?

Hello,
One more question: Could I perform file move operation after file removal during uninstall.
Because I set file removal on removing all files that begins on hosts*, then set file move on moving bk-hosts to hosts in same ../driver/etc folder, but problem is always performs file move then file removal, so renamed hosts file is also deleted.
I'm afraid I don't fully understand your uninstall scenario. Can you please send us the .aip (project file) to support at advancedinstaller dot com and give us more details about the behavior you want to implement on uninstall?
Is it possible to validate ip address in the edit box ?
Yes, this is possible by using a custom action. For example you can use a custom action without sequence which will set the "CHECK_SERVER_IP_FLAG" property (to "valid" or "invalid") based on the "SERVER_IP" property value. Then you can conditionally display a spawn dialog based on your "CHECK_SERVER_IP_FLAG" property value. Also, you can adjust your custom action code like this:

Code: Select all

function ValidateIPaddress(ipaddress)   
{  
 if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))  
  {  
    Session.Property("CHECK_SERVER_IP_FLAG") = "valid";	
    return true;  
  }
Session.Property("CHECK_SERVER_IP_FLAG") = "invalid"; 
return false;  
}  

var sip = Session.Property("SERVER_IP");
ValidateIPaddress(sip);
All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Amanzhol
Posts: 5
Joined: Fri Jul 18, 2014 4:49 am

Re: How do I modify the HOSTS file?

Thanks, Daniel!
Very important question: is it possible to delete modify icon and text from MaintenanceTypeDlg Dialog. I've tried to delete it, redirect it to repair dialog window in its published events, set Disable Modify checkbox from Product Details tab, but no results.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How do I modify the HOSTS file?

Hello,

You cannot delete the [Modify] button, but you can hide and disable it instead. Just select the [Modify] button from "MaintenanceTypeDlg" dialog and from "Properties" right pane set its attributes as follows:
  • Visible: False
    Enabled: False
Also, regarding the "Modify" static text control this can be directly deleted. Please keep in mind that the above dialog editing operation requires our "Dialog Editor" feature which is available only in "Enterprise" or higher project types.

If you have any question let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Amanzhol
Posts: 5
Joined: Fri Jul 18, 2014 4:49 am

Re: How do I modify the HOSTS file?

I'm a bit confused.
I set enabled and visible properties on false value, as you say and in dialog window it's really disappeared, but in installer interface all the same it's visible. I've tried to build and test it several times, but result is same.
Maybe one should change something else, except enabled and visible properties.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How do I modify the HOSTS file?

Hello,

I'm afraid I don't fully understand what you mean Can you please give us more details about the behavior you are encountering (maybe attach some screenshots)?

Do you mean that after setting the above attributes the [Modify] button is still displayed during installation maintenance mode? If so, can you please send us the .AIP (project file) to support at advancedinstaller dot com so we can investigate?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
blindberg74
Posts: 5
Joined: Wed Oct 12, 2016 5:46 pm

Re: How do I modify the HOSTS file?

Hello,
Is there a way to add a new line to the hosts file as opposed to just appending text to the existing line? Especially in the hosts file you need to append a new line not just add your entry to the end of the current line.

Thanks

Return to “Common Problems”