0

I've developed a VSPackage for Visual Studio, which needs to copy some files to Visual Studio's Installation Path.

If I Run Visual Studio as Administrator (when using my installed VSPackage). It can copy files with no errors.

When I run Visual Studio normally, I get Access to the path ... is denied error.

Question

How can I give my VSPackage to admin privileges even when the Visual Studio is being run as a normal user.

Or at least how can I invoke something like this:

enter image description here

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
  • Install your extension as an MSI – ErikEJ Jul 03 '15 at 20:00
  • 1
    I answered one of your other questions some days ago; it answers this question as well... http://stackoverflow.com/questions/30874782/how-get-the-current-running-visual-studio-installation-path-from-vspackage – Matze Jul 04 '15 at 07:24
  • Actually that didn't work for me. Thanks tho – A-Sharabiani Jul 04 '15 at 07:29
  • @Matze I think you better copy your answer here – A-Sharabiani Jul 05 '15 at 22:02
  • @AliSharabiani And then you´re changing the question´s title again to something else and make my answer irrelavant? No, not again my friend (-; – Matze Jul 06 '15 at 13:42
  • @Matze no, previously someone has changed the title of that question, I re-edit it. Also I think talking about these things here is not constructive :) – A-Sharabiani Jul 06 '15 at 14:24

1 Answers1

1

Your package is a .dll (loaded on a process), not an .exe (a process), and therefore it cannot have different privileges than its process (Visual Studio, that is, devenv.exe). What your package can do is to launch a different process with admin rights. See my article:

HOWTO: Launch a process with admin rights from a Visual Studio add-in on Windows Vista or higher.

That said, it is a very wrong approach to do this to copy files to the VS installation path. That should be done by the setup of your package (.msi), not by your package.

On the one hand, if it is done by the package once installed, the user could deny the elevation prompt and the files would not be copied and your installation would be incomplete. Can your package run properly without those files?

On the other hand, if the user denies the elevation prompt to install the package, it wouldn't be installed at all, which is a more clean approach.

Carlos Quintero
  • 4,300
  • 1
  • 11
  • 18
  • My VSPackage updatins some code snippets and xml schema files in Visual Studio. To do this, the package should download the files from a server (whenever new files are available), and copy them in Visual Studio's folder.Also every time user can force update snippets and schemas by clicking a command on the menu bar. Snippets are being updated regularly on the server . That being said we copy files more than once. So msi cannot be an option. What do you think the best approach for implementing this is? Thanks. – A-Sharabiani Jul 04 '15 at 15:38
  • I am not sure about xml schema files, but about code snippets Visual Studio allows per-user code snippets that are stored in C:\Users\\Documents\Visual Studio \Code Snippets. I guess there must be an API to import them there, and it shouldn't require admin rights because they are per-user. – Carlos Quintero Jul 05 '15 at 15:38
  • 2
    If admin rights are required, then the only way is a second process that copies them, with an elevation prompt. – Carlos Quintero Jul 05 '15 at 15:39