Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating Hosts file on the local PC using Login Script

Posted on 2014-01-19
9
Medium Priority
?
2,695 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 70

Accepted Solution

by:
KCTS earned 668 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 37

Assisted Solution

by:Mahesh
Mahesh earned 336 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 332 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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 664 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 668 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 664 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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