{"id":62,"date":"2014-12-18T14:56:06","date_gmt":"2014-12-18T14:56:06","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=62"},"modified":"2014-12-18T14:56:06","modified_gmt":"2014-12-18T14:56:06","slug":"changing-or-virtualizing-the-hosts-file-with-appv-5","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2014\/12\/changing-or-virtualizing-the-hosts-file-with-appv-5\/","title":{"rendered":"Changing or virtualizing the Hosts file with AppV 5"},"content":{"rendered":"<p>Sometimes, applications require specific host file entries. Often you&#8217;d probably be able to get around using DNS to resolve the entries the application really needs. But when you can&#8217;t, and you want to virtualise your application using AppV 5, it&#8217;ll use the hosts file of the OS instead of the hosts file in the virtualized file system.<\/p>\n<p>To get around this, we can let the AppV client fire off a script to modify the actual OS hosts file upon registration of the AppV application. This is done by modifying the DeploymentConfig.xml file and adding a script to your package, detailed descriptions of how this works can be found <a href=\"http:\/\/blogs.technet.com\/b\/appv\/archive\/2012\/12\/10\/scripting-and-embedded-scripting-for-appv-5-0-dynamic-deployment-and-user-configuration-scripting.aspx\">here<\/a>. Basically, you add this between the &lt;Machinescripts&gt; tags in the DeploymentConfig.xml file, example:<\/p>\n<pre><AddPackage>;\n <Path>c:\\windows\\system32\\wscript.exe<\/Path>\n <Arguments>{AppVPackageRoot}]\\Scripts\\hostfile_edit.vbs<\/Arguments>\n <Wait RollbackOnError=\"true\" Timeout=\"10\"\/>\n <\/AddPackage><\/pre>\n<p>The VB code\u00a0in hostfile_edit.vbs\u00a0that does the actual work is:<\/p>\n<pre>Const ForReading = 1, ForWriting = 2, ForAppending = 8\n Set fso = CreateObject(\"Scripting.FileSystemObject\")\n Set WshShell = CreateObject(\"WScript.Shell\")\n WinDir = WshShell.ExpandEnvironmentStrings(\"%WinDir%\")\n HostsFile = WinDir & \"\\System32\\Drivers\\etc\\Hosts\"\n Set filetxtR = fso.OpenTextFile(HostsFile, ForReading, True)\n DNSEntry1 = \"10.0.0.1 HOSTNAME\u00a0#DESCRIPTION\"<\/pre>\n<pre>If (checkHostfile(filetxtR, DNSEntry1) = True) Then\n WScript.Quit(0)\n Else\n Set filetxtA = fso.OpenTextFile(HostsFile, ForAppending, True)\n filetxtA.WriteLine (DNSEntry1)\n filetxtA.Close\n End If<\/pre>\n<pre>filetxtR.Close\n WScript.Quit(0)<\/pre>\n<pre>Public Function checkHostfile(filetxt, lineToCheckFor)\n checkHostfile = False\n Do Until filetxt.AtEndOfStream\n s = filetxt.readline\n If (s = lineToCheckFor) Then\n checkHostfile = True\n Exit Function\n End If\n Loop\n filetxt.Close\n End Function<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, applications require specific host file entries. Often you&#8217;d probably be able to get around using DNS to resolve the entries the application really needs. But when you can&#8217;t, and you want to virtualise your application using AppV 5, it&#8217;ll use the hosts file of the OS instead of the hosts file in the virtualized &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2014\/12\/changing-or-virtualizing-the-hosts-file-with-appv-5\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Changing or virtualizing the Hosts file with AppV 5<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-62","post","type-post","status-publish","format-standard","hentry","category-appv5"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}