Petri IT Knowledgebase Forums
 

Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > General Scripting
Petri.co.il is happy to award auglan the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read

Notices

Batch File creation - Help Needed.

Batch File creation - Help Needed.

this thread has 4 replies and has been viewed 6661 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 29th June 2005, 23:00
Bladerunner Bladerunner is offline
Casual
Casual
 
 Join Date: Apr 2005
  6 month star 12 month star
 Posts: 6
 Reputation: Bladerunner is on a distinguished road (10)
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
  #2  
Old 29th June 2005, 23:18
stoo.mp stoo.mp is offline
Casual
It's not a coincidence
 
 Join Date: Jun 2005
  6 month star 12 month star
 Location: Wiltshire, UK
 Posts: 71
 Reputation: stoo.mp is on a distinguished road (10)
Default RE: Batch File creation - Help Needed.

Hi,

Use 'XCOPY' not 'COPY'

XCOPY is much more powerful

Open a command prompt window (START > RUN > type CMD press Enter)

type: XCOPY /?

This shows the switches you can use with the XCOPY command.

Quote:
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
[/EXCLUDE:file1[+file2][+file3]...]

source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set,
doesn't change the attribute.
/M Copies only files with the archive attribute set,
turns off the archive attribute.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. Each string
should be in a separate line in the files. When any of the
strings match any part of the absolute path of the file to be
copied, that file will be excluded from being copied. For
example, specifying a string like \obj\ or .obj will exclude
all files underneath the directory obj or all files with the
.obj extension respectively.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/V Verifies each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/G Allows the copying of encrypted files to destination that does
not support encryption.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
/U Copies only files that already exist in destination.
/K Copies attributes. Normal Xcopy will reset read-only attributes.
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.
Just use the switches after the lines in your BAT file... you'll probably want to use the /Y switch though to overwrite if the file exists.

Hope that helps...

__________________
1 + 1 = 11 ... honest!
  #3  
Old 30th June 2005, 23:10
Dumber's Avatar
Dumber Dumber is offline
Moderator
 
 Join Date: Dec 2003
  6 month star 12 month star
 Location: The Netherlands
 Posts: 8,067
 Reputation: Dumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to behold (820)
Default RE: Batch File creation - Help Needed.

just add the following line instead of those 2 lines:

Code:
copy /y <CDDRIVE>\dir\hosts "%windir%\system32\drivers\etc\hosts
if this won't work, you can indeed use xcopy instead of copy
__________________
Marcel
Netherlands
http://www.phetios.com
http://blog.nessus.nl

MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
No matter how secure, there is always the human factor.
  #4  
Old 1st July 2005, 10:12
topper's Avatar
topper topper is offline
Member
Someone to look up to
 
 Join Date: Apr 2005
  6 month star 12 month star
 Location: Leeds, England.
 Posts: 741
 Reputation: topper is just really nicetopper is just really nicetopper is just really nicetopper is just really nice (356)
Default RE: Batch File creation - Help Needed.

Quote:
Originally Posted by Dumber
just add the following line instead of those 2 lines:

Code:
copy /y <CDDRIVE>\dir\hosts "%windir%\system32\drivers\etc\hosts
if this won't work, you can indeed use xcopy instead of copy
That should work fine, but remember you'll have to be an Admin on the machine for the overwrite to work.

topper
__________________
There are 10 types of people in this world, those who understand binary and those who do not.
  #5  
Old 3rd July 2005, 00:37
Bladerunner Bladerunner is offline
Casual
Casual
 
 Join Date: Apr 2005
  6 month star 12 month star
 Posts: 6
 Reputation: Bladerunner is on a distinguished road (10)
Default Thanks!

Thanks for the reply, it worked a treat!

Bladerunner
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Needed for Outlook Express's Damaged .dbx file alitoday Outlook XP/2003/2007 1 4th February 2006 13:25
Run a batch file @ shutdown Solid Windows 2000 Pro, XP Pro 8 19th January 2006 20:41
Batch file copy from cd? Bladerunner General Scripting 6 17th April 2005 23:41
PHP extensions installations , IIS crash after enable mbstri igoldman Windows Server 2000 / 2003 0 7th April 2005 10:42
Batch File Michellea General Scripting 1 24th January 2005 12:47


All times are GMT +3. The time now is 17:57.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri