如何为我的 VSPackage 授予管理员权限? [英] How to give Administrator Privileges to my VSPackage?

查看:55
本文介绍了如何为我的 VSPackage 授予管理员权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 Visual Studio 开发了一个 VSPackage,需要将一些文件复制到 Visual Studio 的安装路径.

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

如果我以管理员身份运行 Visual Studio(使用我安装的 VSPackage 时).它可以无误地复制文件.

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

当我正常运行 Visual Studio 时,出现 Access to the path ... is denied 错误.

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

问题

即使 Visual Studio 以普通用户身份运行,我如何才能将 VSPackage 授予管理员权限.

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:

推荐答案

您的包是 .dll(加载到进程上),而不是 .exe(进程),因此它不能具有与其进程不同的权限(Visual Studio,即 devenv.exe).您的包可以做的是启动具有管理员权限的不同进程.看我的文章:

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:从 Windows Vista 上的 Visual Studio 加载项启动具有管理员权限的进程或更高.

也就是说,将文件复制到VS安装路径是一种非常错误的做法.这应该通过设置您的程序包 (.msi) 来完成,而不是通过您的程序包.

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.

这篇关于如何为我的 VSPackage 授予管理员权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆