Copy files from build events within Visual Studio without Windows UAC problems
In my projects, I often have to copy some files in either a pre-build or post-build event within Visual Studio. Since installing Windows 7, it seems that the copy command from those build events generates an error with a not very helpful message such as the following one:
The “..exited with code 1” leaves me dreaming about a ton of causes for this error. When manually copying the file to the destination directory (as copying AmazonBookLinker.dll to C:\Program Files\Windows Live\Writer\Plugins\) via Windows Explorer, I get the following second strike:
At this point, I’m playing around with security permissions for both files and destination directory without any positive result. The solution I came about this problem is to actually run Visual Studio with administrator privileges by right-clicking your Visual Studio file icon, and selecting “Run as administrator”. If you want to make this a permanent solution:
- Open the properties window for Visual Studio
- Go to the Compatibility tab
- Under the “Privilege Level” box, check the “Run this program as an administrator”
- Click on OK
- [Optionally] Click on the “Change settings for all users” button apply this privilege to all users on the machine.
Similar posts you might be interested in reading:
- "Copying a file too large for the destination file system"…Yeah, right!
- Installing NVIDIA drivers on Windows 7
- Integrating Enterprise Library 3.1 Configuration Tool in Visual Studio 2008
- Migrating a Wordpress site from BlueHost to WebHost4Life
- Quick access to useful documents inside Visual Studio
- Using the “Source Control – Team Foundation” toolbar to perform common TFS operations on the current document within Visual Studio
- Mapping a domain name to an IP address in the HOSTS file to bypass a DNS resolver.






Arjan’s World » LINKBLOG for August 17, 2009:
[...] Copy files from build events within Visual Studio without Windows UAC problems – Brian di Croce [...]
August 17, 2009, 9:00 amHimesh:
Hi Brian,
Thanks for posting this!
I’ve been looking long and hard for someone that’s had the same issue.
Do you know if anyone running Windows 7 has gotten past this problem? I’ve turned off UAC in Win7 (selected the lowest level possible) which, I think, automatically runs all apps in Admin mode. But I’m still getting the exit with code 1 error. (Which btw, if you take a look at the Output tab in VS actually tells you that access was denied to the copy command). I then went ahead and completed the steps you mentioned in this post to explicity run VS in Admin mode but the pre-build event still fails.
Hope you have a solution for this..
August 26, 2009, 7:17 amThanks for your time dude,
Himesh