Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

wpf - 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.

The application .EXE in Program Files does allow this option on right-click. If I created the shortcut manually from the .EXE (i.e. "Create Shortcut") instead of from the deployment, then the resulting shortcut also has that option.

How to a deploy an application in Visual Studio Installer to include a shortcut that has "Run as Administrator" option enabled on right-click?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I spent ages looking for a solution to this. Amazing, really, as it must be the case for all Visual Studio installer projects.

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.

Apparently this is an issue with the resulting .msi where the shortcut created is an "advertising shortcut". 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. 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.

Full credit to the guys on this SO post for this solution, btw. 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. You'll need Orca to make the initial change.

  1. Download the Windows SDK Installer here.

  2. Select "MSI Tools" in the installer.

  3. Install Orca-x86_en-us found in {Installation Folder}Windows Kits10WindowsSDKInstallers.

  4. Find the file "Schema.msi" which is located somewhere like {Visual Studio Program Folder}Common7IDECommonExtensionsMicrosoftVSIinVsdSchema.

  5. Open "Schema.msi" in Orca.

  6. Copy the folder to the Desktop if it is read only and replace the original after step 9.

  7. Select the "Property" table on the left.

  8. Add a table row with property DISABLEADVTSHORTCUTS and value "1" (true).

  9. Save the file and close 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. So check the msi file after each update.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...