depending on when you need it updated i meant. if you need it updated daily once, just use a scheduled event to run the batch file with admin rights, you'll just set it to run as then put in an admin name and pw.
Main Topics
Browse All TopicsHello experts.
I'm trying copy an edited host and lmhosts.sam file to the c:/windows/system32/driver
__________________________
cd\
cd c:/windows/system32/driver
copy \\server\host_files\hosts /y
copy \\server\host_files\lmhost
exit
__________________________
However I'm only able to run this successfully when an account with administrative rights logs into the computer. Is there any way to have this run successfully when regular users log into their accounts through login script? Or does anyone have an alternate way to update this file with other means?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Right click My Computer> Manage. Navigate to Local Users and Groups>Users in the left hand pane. In the right side, double click the user you want to add the script for and click on 'Profile' tab. You can add the batch file to the logon script. Unless the script is in the %Systemroot% folder, you will have to type the full path of the script.
The problem is coming up because the Hosts and LMHosts files are set for Read perms only for Users by default. If you change this, then your batch file will work.
But this begs the question, what are you changing in it? If it's just the odd IP address now and again, I'd create a batch file that you run manually, with a loop to apply it to each pc, and write a status error as well...
hth Danny
amir: This may be helpful if each user is all on one local machine. I'd prefer not need to go to each individual machine and add the login script locally for each user. That would take forever. I've assigned this batch file through Active Directory Group Policy logon script, which is more suitable to add for network users. However the problem is not running the script, it's the fact that because of permission levels, when the batch file runs, it comes back with an "Access Denied".
Dan: Is there a way to change the perms to read/write for each machine without having to physically go to each one and do it manually?
The reason I am replacing the host file is because I found that some had a list of IP addresses that point to our servers using their public IP addresses instead of their private addresses in which resolve through DNS. I'm basically just replacing the host file to not have any addresses listed. This was causing some problems accessing application and database servers remotely through vpn.
group policy is the easiest way to deal with this.
If you copy the file over one time, you can set the perms on the file before you copy it, and then they'll be there forever. Then your login script would work. However, by relaxing the perms, you do run the risk that a) users will fiddle, and b) that unwanted stuff can get to the files - adware redirects and pharming risks too.
Batch file stuff:
the NET VIEW command, redirected to a text file can give a fairly tidy list of pcs on the domain
C:\> net view > c:\list.txt
might need a bit of tweaking to remove stuff at the start and end, and I think you need to be careful with the \\ too. Open it in Word and use Find.. Replace. Sorry, bit rusty on this.
then in a batch file
FOR /F " tokens=1 " %%i in (list.txt) do copy lmhosts.sam "%%i\C$\windows\system32\d
test with a list of a few pcs, and check the results.txt file for the outcome
Dan: Not sure what you mean by "If you copy the file over one time, you can set the perms on the file before you copy it, and then they'll be there forever."
also,
then in a batch file
FOR /F " tokens=1 " %%i in (list.txt) do copy lmhosts.sam "%%i\C$\windows\system32\d
Do i copy that line "FOR /F " tokens=1 " %%i in (list.txt) do copy lmhosts.sam "%%i\C$\windows\system32\d
I don't think it's what you want but the below will work:
You can access the Admin share (C$)
if you have admin un/pw for each client you can access them with the net use command.
NET USE
[devicename | *] [\\computername\sharename[
[/USER:[domainname\]userna
[/USER:[dotted domain name\]username]
[/USER:[username@dotted domain name]
[/SMARTCARD]
[/SAVECRED]
[[/DELETE] | [/PERSISTENT:{YES | NO}]]
NET USE {devicename | *} [password | *] /HOME
NET USE [/PERSISTENT:{YES | NO}]
eg..
net use * \\COMPUTER(or IP address)\c$ /user:administrator password
BTW, you'd have to do one of 2 things for it to work. First, would be to grant read access to the "Domain Computers" AD group to the network share the hosts files are located on so that the system accounts can connect to it.
Or, modifiy the script to map a drive using "net use" specifying a username and password, copying the files, then disconnecting the drive.
Ken: That didn't seem to do anything. Once I set the computer startup script, Start|Run|typed gpupdate /force, rebooted, all seemed well as it said it was running the startup script. However when checking the host file, it looked to be the original, and not replaced. Are you sure the startup script uses the system account with admin privileges? I think the only obstacle here is permission level for the system folders. There's got to be a way to accomplish this...
Hmm, it could be using a null session when the system account is running the script. On the server computer, go to HKEY_LOCAL_MACHINE\SYSTEM\
More information about can be found at http://support.microsoft.c
Inlcuding how to allow NullSessionPipes if needed etc.
Ken: Thanks for the suggestion, however I'm a little hesitant to edit the registry at this time as I'm not exactly sure how to add the name of the host file to the REG_MULTI_SZ value, as it states:
"On a new line in the NullSessionPipes key, type the name of the pipe that you want to access with a null session."
If you are more familiar with how to do this, let me know. Also, this would require a reboot, and I won't be able to reboot the server during business hours, so I won't know if the results have taken any effect until the following day.
Business Accounts
Answer for Membership
by: DoTheDEW335Posted on 2005-04-13 at 11:48:18ID: 13775382
you might be able to schedule it to run and have it "run as" an administrator. I'm not quite sure how you could schedule it to run when they logon though.