Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File Help

Status
Not open for further replies.

rr27

MIS
Nov 18, 2005
69
US
Here's the deal I'm writing a batch file that will copy a file to the users desktop but I don't want the script to overwrite the file if it already exists. How do I write a if statement to prevent this. I have never used a if statement in a batch file before. Please help..........
 
rr27,
at a command prompt type if /?
you will see that there is a switch to check if a file exists. if it does then do nothing, if it doesn't then dopy.
regards,
longhair
 
Great Thanks, Now I have a new problem here is what my batch file looks like:

copy \\s01\re_test\"client classic.lnk" "C:\Documents and Settings\All Users\Desktop"
IF EXIST C:\winnt\camx3.ini goto INI_Exists
copy \\s01\re_test\camx3.ini c:\winnt\
copy \\s01\re_test\xcacls.exe c:\winnt
xcacls c:\winnt\camx3.ini /E /G everyone:F
echo User=%user% >>c:\winnt\camx3.ini
goto END
:INI_Exists
copy \\s01\re_test\xcacls.exe c:\winnt
xcacls c:\winnt\camx3.ini /E /G everyone:F
echo [Login] >>c:\winnt\camx3.ini
echo User=%user% >>c:\winnt\camx3.ini
echo Server=p01 >>c:\winnt\camx3.ini
echo Domain=lat >>c:\winnt\camx3.ini
:END

The problem is domain user accounts are getting Access Denied messages. How can I get this script to work. Please note I am not running a Active Directory domain, but all of my 300+ client computers run Windows 2000 or Windows XP.
 
rr27,
do the users have rights to write to c:\winnt? usually this is not allowed.
regards,
longhair
 
I guess they don't.... Any idea on how I can accomplish the purpose of this batch file?????
 
rr27,
change the location of the local file you are writing to? can you put it in the root of c:\ rather than c:\winnt? not sure if this will cause another issue because one of the files that you are echoing to is an .ini.
regards,
longhair
 
I tried copying to the c:\ and get access denied. I even get access denied we trying to copy a file to the users desktop. Please help............. The one of the files needs to go to the c:\winnt\ folder.
 
rr27,
if you need to write to c:\winnt then what ever account is running the batch job needs rights to that folder. So, if the batch job is run as your domain user with their password then that user has to have read - write - modify - etc fot c:\winnt.
please note that this is dangerous and i would not advise it. once the user has rights to this directory they can actively make a change or accidentally make a change (virii, malware, spyware, etc).
regards,
longahair
 
This script is going to as a login script... Can you run the runas command in DOS??? If so how?
 
rr27,
at a cmd prompt type 'runas /?' to see usage. i do not think it fits your requirements. since there is a prompt for the password.
i do not understand the requirement to write to c:\winnt - to an .ini file. what is calling the .ini file?
regards,
longhair
 
From what you've told us I would try something like this. Some of this depends on how the software works.

Make a computer startup script that copies the .ini file to the appropriate place. Then you know that its where it should be and you wont have to worry about the users permissions. Apply that to the appropriate GPO.

Adjust the users login script to append to the .ini file.

You may need to move the .ini file to the executable's directory. Where is should be found. Or make a child directory off of c:\ and adjust the PATH to find it. _Should_ work but you'd have to test it.

Id try to avoid allow users to write to c:\ it just makes me nervous. ;-)
 
OK I think I'm on to some thing ..... If I use the runas command in the batch file is their a way I can automatically insert the password so it doesn't prompt the user.
 
I actually found a way to work around this issue. Can you use a "or" statement in a bath file for example
c:\winnt or c:\windows ????
 
if the files are the same on xp or 2000 and located in either c:\winnt or c:\windows you could try using the system variable 'Windir' in your batch file


an example from your script would be

echo User=%user% >>%windir%\camx3.ini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top