简体   繁体   English

VS 安装程序的快捷方式中缺少“以管理员身份运行”

[英]Missing “Run as Administrator” in VS Installer's Shortcut

I created a shortcut from the application .EXE in Visual Studio Installer , but the resulting shortcut did not have the option of " Run as Administrator " when I right-clicked the shortcut icon.我从Visual Studio Installer 中的应用程序.EXE创建了一个快捷方式,但是当我右键单击快捷方式图标时,生成的快捷方式没有“以管理员身份运行”的选项。

The application .EXE in Program Files does allow this option on right-click. Program Files 中的应用程序.EXE允许右键单击此选项。 If I created the shortcut manually from the .EXE (ie " Create Shortcut ") instead of from the deployment, then the resulting shortcut also has that option.如果我从.EXE (即“创建快捷方式”)而不是从部署中手动创建快捷方式,则生成的快捷方式也具有该选项。

How to a deploy an application in Visual Studio Installer to include a shortcut that has " Run as Administrator " option enabled on right-click?如何在Visual Studio 安装程序中部署应用程序以包含在右键单击时启用“以管理员身份运行”选项的快捷方式?

I spent ages looking for a solution to this.我花了很长时间寻找解决方案。 Amazing, really, as it must be the case for all Visual Studio installer projects.真的很棒,因为所有 Visual Studio 安装程序项目都必须如此。

I'm using Visual Studio 2017 Community at the time of writing and I can't see any option to do this from within the IDE.在撰写本文时,我正在使用 Visual Studio 2017 社区,但在 IDE 中看不到任何执行此操作的选项。

Apparently this is an issue with the resulting .msi where the shortcut created is an "advertising shortcut".显然,这是生成的.msi的问题,其中创建的快捷方式是“广告快捷方式”。 I'll leave you to discover what you want to know about that in your own time.我会让你在你自己的时间发现你想知道的。 (Personally, I don't care.) (就我个人而言,我不在乎。)

What you need to do is force the shortcut to be "non-advertising".您需要做的是强制快捷方式为“非广告”。

This is the better of the two solutions I've found squirreled away in SO.这是我在 SO 中发现的两个解决方案中更好的一个。 I think it's better because it 1) doesn't include adjusting your installer project for each solution and 2) doesn't involved manually editing the .msi file after every build.我认为它更好,因为它 1) 不包括为每个解决方案调整安装程序项目,2) 不涉及在每次构建后手动编辑.msi文件。

Full credit to the guys on this SO post for this solution, btw.顺便说一句,对于此解决方案, 此 SO 帖子上的人员完全归功于此。 You know who you are.你知道你是谁。 I'm posting because it's not obvious from the question that it will solve this particular problem.我发帖是因为从问题中看不出它会解决这个特定问题。

What you do is make a generic change to the msi creation schema file so that the change propagates to all of your future builds.您所做的是对 msi 创建架构文件进行通用更改,以便更改传播到您未来的所有构建中。 You'll need Orca to make the initial change.您需要 Orca 来进行初始更改。

  1. Download the Windows SDK Installer here .此处下载 Windows SDK 安装程序。

  2. Select "MSI Tools" in the installer.在安装程序中选择“MSI 工具”。

  3. Install Orca-x86_en-us found in {Installation Folder}\\Windows Kits\\10\\WindowsSDK\\Installers .安装位于{Installation Folder}\\Windows Kits\\10\\WindowsSDK\\Installers 中的Orca-x86_en-us。

  4. Find the file "Schema.msi" which is located somewhere like {Visual Studio Program Folder}\\Common7\\IDE\\CommonExtensions\\Microsoft\\VSI\\bin\\VsdSchema .找到位于{Visual Studio Program Folder}\\Common7\\IDE\\CommonExtensions\\Microsoft\\VSI\\bin\\VsdSchema 之类的文件“Schema.msi”。

  5. Open "Schema.msi" in Orca.在 Orca 中打开“Schema.msi”。

  6. Copy the folder to the Desktop if it is read only and replace the original after step 9.将文件夹复制到桌面(如果它是只读的)并在步骤 9 后替换原始文件夹。

  7. Select the "Property" table on the left.选择左侧的“属性”表。

  8. Add a table row with property DISABLEADVTSHORTCUTS and value "1" (true).添加具有属性DISABLEADVTSHORTCUTS和值“1”(真)的表行。

  9. Save the file and close Orca.保存文件并关闭 Orca。

  10. Rebuild your installer project and (re-)deploy your application.重建您的安装程序项目并(重新)部署您的应用程序。

  11. Enjoy the ability to "Run as administrator"!享受“以管理员身份运行”的能力!

A final note: I've found that updates to Visual Studio can overwrite the change you've made, once again removing the "Run as Administrator" context option.最后一点:我发现 Visual Studio 的更新可以覆盖您所做的更改,再次删除“以管理员身份运行”上下文选项。 So check the msi file after each update.所以每次更新后检查 msi 文件。

If you have a manifest, you can require to have administrator privilege, add the following to your manifest如果您有清单,则可以要求具有管理员权限,将以下内容添加到清单中

<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

see http://msdn.microsoft.com/en-us/library/bb756929.aspx请参阅http://msdn.microsoft.com/en-us/library/bb756929.aspx

You can also run any filetype as administrator with the help of the registry, see http://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-to-any-file-type-in-windows-vista/您还可以在注册表的帮助下以管理员身份运行任何文件类型,请参阅http://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-to-any-file-type-in​​-视窗远景/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WiX 安装程序应始终以管理员身份运行 - WiX installer should always run as administrator 任何人都可以在VS2008(C#)Pro中创建安装程序的好“白痴指南”吗? - Can anyone provide a good “idiot's guide” to creating an installer in VS2008 (C#) Pro? 如何以管理员身份在另一台计算机上运行WPF应用程序 - How to run a WPF application on an other computer, as administrator 如何强制 WPF 应用程序在管理员模式下运行 - How to force a WPF application to run in Administrator mode 如何在VS 2012中为WPF创建安装程序 - How to create an installer for WPF in VS 2012 具有C#WPF VS 2015的MSI安装程序 - MSI installer with c# WPF VS 2015 VS 2019 上的 WPF .NET Core 安装程序 - WPF .NET Core Installer on VS 2019 如何强制我的项目在Visual Studio 2013中始终以管理员身份运行? - How to force my project in Visual Studio 2013 to always run as Administrator? 不以管理员身份运行时App.Config文件被错误读取 - App.Config file being read incorrectly when not run as administrator (InstallShield)WPF可执行文件如果未以管理员身份运行,则调用错误的dll版本 - (InstallShield) WPF Executable Calls wrong dll version if not run as administrator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM