Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Batch File creation - Help Needed.
Closed Thread
Old 06-29-2005, 03:54 PM   #1 (permalink)
 
Newb Techie

Join Date: Apr 2005

Posts: 4

Bladerunner2019

Default Batch File creation - Help Needed.

Hi

Ive created a cd that autoruns a graphical menu with clickable links, and one of the links points to a HOSTS.bat file that copies over a custom HOSTS file from the cd to the ..\drivers\etc folder on the system root.

The problem I'm having is that I'm unsure of the correct syntax to use to automatically overwrite the existing HOSTS file.

I need to write it to work on both Win2K and XP machines, so have included two lines; one copies the HOSTS file to WINDOWS\system32\drivers\etc, and one copies it to Winnt..\etc. Thsi seems to work ok, for if it's an XP machine it ignores the Winnt instruction and vica versa.

However, this has all been tested with my original HOSTS file temporarily renamed to HOSTS2, so there is no HOSTS file to be overwritten. I cannot seem to make it work if there is a HOST file already present.

Is there a switch to make it overwrite? Or changing tack entirely, is there a way I can instruct the IP address I need to be written into the original HOSTS file?

Here is the contents of the batch file as it stands:

rem

copy "hosts" "C:\WINDOWS\system32\drivers\etc\hosts"

copy "hosts" "C:\WINNT\system32\drivers\etc\hosts"

If anyone can help I would be most appreciative!

TIA ;-)
Bladerunner2019 is offline  
Old 06-29-2005, 05:04 PM   #2 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default

What error does it respond with when you try to replace the host file?

put a "pause" at the end of your batch file so you have time to read the error message.

Are you going to be using this under users with administrator access, power user or user access?

Under the administrator account it works perfectly to just use the copy command.

If it's prompting for confirmation of the replacement, you can do the following

Code:
 copy -y location destination

__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
Old 06-29-2005, 05:26 PM   #3 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default

I'm headed home from work, where I use my mac, so here's a copy of the batch file that I would use.

Code:
@echo off

copy /y hosts c:\windows\system32\drivers\etc\
copy /y hosts c:\winnt\system32\drivers\etc\
If you wanted to make it a bit more fool proof, I'd check if Winnt exists vs Windows.

Code:
@echo off

if exist c:\winnt\ (
copy /y hosts c:\winnt\system32\drivers\etc
) else (
copy /y hosts c:\windows\system32\drivers\etc
)
Lastly, if that still doesn't work on your system, you could always rename the file, then copy the new one.

Code:
@echo off

if exist c:\winnt\ (
rename c:\winnt\system32\drivers\etc\hosts hosts.bak
copy hosts c:\winnt\system32\drivers\etc\
) else (
rename c:\windows\system32\drivers\etc\hosts hosts.bak
copy hosts c:\windows\system32\drivers\etc\
)

__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
Old 07-02-2005, 05:16 PM   #4 (permalink)
 
Newb Techie

Join Date: Apr 2005

Posts: 4

Bladerunner2019

Default Solved!!

Thanks for the response bla!!
However, I've now solved it - although I believe your suggestion would indeed work, I've discovered the only code I need is the following:

rem

copy /y HOSTS "%windir%\system32\drivers\etc\HOSTS"

This gets around the problem of there being differently named windows system folders.

Thanks again bla!!

Bladerunner2019

;-)
Bladerunner2019 is offline  
Old 07-02-2005, 05:26 PM   #5 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default

Nice, I always forget to take advantage of the local variables mapped at startup.
__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On