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:

imageThe “..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:

imageAt 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:

  1. Open the properties window for Visual Studio
  2. Go to the Compatibility tab
  3. Under the “Privilege Level” box, check the “Run this program as an administrator
  4. Click on OK
  5. [Optionally] Click on the “Change settings for all users” button apply this privilege to all users on the machine.

image

This post has been viewed: 5096 times. kick it on DotNetKicks.com

 

Similar posts you might be interested in reading:

2 Comments

  1. Arjan’s World » LINKBLOG for August 17, 2009:

    [...] Copy files from build events within Visual Studio without Windows UAC problems – Brian di Croce [...]

  2. Himesh:

    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..
    Thanks for your time dude,
    Himesh

Leave a comment

Powered by WP Hashcash