Solved

Updating Hosts file on the local PC using Login Script

Posted on 2014-01-19
9
2,389 Views
Last Modified: 2014-01-29
Hi,
 
 I have hosts file that changes from time to time due to the fact that we host several websites internally on our web server with IP address 192.168.1.4. When the users open the browser and type in ABC.com, NBC.com, CBS.com, I want the browser to go directly to my web server instead of going to the Internet to find those websites (because they are running within the network). But this requires updating hosts file (located in
C:\WINDOWS\system32\drivers\etc ) on each workstation PC  to reflect the new website addition or what have you.

192.168.1.4     ABC.com
192.168.1.4     NBC.com
192.168.1.4     CBS.com

xcopy \\DC1\share\hosts C:\WINDOWS\system32\drivers\etc /c /y

Is there a way to incorporate the XCOPY command above (that copies newest hosts file on the network Share folder and replace the hosts file on workstation PC) automatically as a part of login process?

Thanks.
0
Comment
Question by:sglee
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 70

Accepted Solution

by:
KCTS earned 167 total points
ID: 39792392
Why use the hosts file - use your DNS server and make the entries there - only one place to make the changes when needed and no need to do anything to the clients.
0
 
LVL 36

Assisted Solution

by:Mahesh
Mahesh earned 84 total points
ID: 39792414
yes, that's absolutely right.

However You can use GP preferences to achieve that
http://serverfault.com/questions/298138/deploy-hosts-file-among-machines-connected-to-a-domain

GP preferences are compatible on Win Vista and above natively

You can use it on Win XP once you install below patch on XP
http://www.microsoft.com/en-in/download/details.aspx?id=3628

Mahesh
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 83 total points
ID: 39792486
And your 'hosts' file is often restricted by your anti-virus program so that it can't be easily changed.  Changes to the 'hosts' file used to be a favorite attack method to redirect browsers from some place like Google to a malware site.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:sglee
ID: 39792554
@kcts
DNS is where I wanted to do too. However I was not able to get needed help on this board when I posted the question.
0
 
LVL 19

Assisted Solution

by:deroode
deroode earned 166 total points
ID: 39793808
You would place the xcopy command in a Startup script, as it runs in the local system context, and thus has the rights to update this file. The logon script runs in the local user context, and has no rights to update the hosts file.
0
 

Author Comment

by:sglee
ID: 39804340
@ deroode

I have this xcopy command that I like to insert into user login script file.
--------------------------------
xcopy \\DC1\share\hosts C:\WINDOWS\system32\drivers\etc /c /y
--------------------------------


Here is a sample Login Script "Users.bat" in \\DC1\netlogon folder on the file server.
--------------------------------
net time \\DC1 /set /yes
net use F: \\DC1\%username%
net use G: \\DC1\Share
--------------------------------

Can you show me how to integrate my XCOPY command into the user login script so that hosts file is copied to local PC every time users log in to the network?
0
 
LVL 70

Assisted Solution

by:KCTS
KCTS earned 167 total points
ID: 39804515
It does not make sense to change the host file in this way

Simply go to the DNS console, right click and add/edit an  A record for the desired IPs
http://www.youtube.com/watch?v=WYj7KSIn2Xo
0
 

Author Comment

by:sglee
ID: 39804544
@KCTS
Thanks for the link. I will try that tonight and get back to you.
0
 
LVL 19

Assisted Solution

by:deroode
deroode earned 166 total points
ID: 39805912
As stated before: Do not add the Xcopy command to the user login script, but to the computer startup script; Users don't have the right to update the Hosts file;

Create or edit a policy wich is associated to your workstations, goto Computer configuration - Windows Settings - Scripts (Startup/Shutdown); Create a startup script (e.g. \\domain\netlogon\startup.cmd) and put your Xcopy command in there.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question