views:

2287

answers:

3

I have this batch that needs to run that the user has to execute that will copy a simple xml file. However, everything works fine on windows 2000/XP. However, on windows Vista I get an error 'Access Denied".

Even when I try and copy the file just using windows explorer on Vista I get the same error.

Is there anything I can do to make this file copy. Do I have to add any extra code to my bat file to enable copying of this file?

Many thanks.

@ECHO OFF
REM copy config file to the windows/system32
copy config.xml c:\windows\system32\DataLinks.xml
+5  A: 

I'm guessing it's because you're trying to change windows\system32. Vista, 7 and future version of Windows require elevated privileges in order to change system32.

Do you really need to put this file in system32? If it's an arbitrary location, why not pop it in the user's AppData directory (%AppData%\DataLinks.xml)?

AppData is a standard directory that's been around since Windows 2000 that hides in the user's Documents and Settings or Users folder (depending on the version). It's a hidden but user-editable folder, intended for application settings that the user needs to be able to get to but is mostly only going to be used by your code.

Merus
Hello, Yes. I think that would be a better idea. However, does windows xp have the same folder? As this would be installed on both xp/vista and possibly future editions of windows?
robUK
He said ".. that's been around since Windows 2000 .."
kitchen
I edited that in as a response, though.
Merus
"Been around since Windows 2000". Sorry wasn't thinking straight. Thanks
robUK
+2  A: 
  1. You need elevated privs to copy to %windir%\system32
  2. You shouldn't copy your config data into %windir% at all. That's for Windows. Use %AppData%.
  3. If you do copy to %windir%, use the %windir% variable and don't hardcode the path C:\Windows
JSBangs
A: 

JS Bangs is right; use %windir% variable. Most of the time when you do that it won't give any errors.

Example:

@ECHO OFF
REM copy config file to the windows/system32
copy config.xml %windir%\system32\DataLinks.xml

But while would you? Just put it in any other one. Like AppData what was already said:

@ECHO OFF
REM copy config file to the windows/system32
copy config.xml %appdata%\DataLinks.xml
YourComputerHelpZ