Jaroslav Cap
Jaroslav Cap

Reputation: 1

Run as administrator on an link using Inno Setup 6.3

When there is a need to configure a shortcut created by an Inno Setup installation package, the approach mentioned in the topic "How to set 'Run as administrator' on a file using Inno Setup" (URL here: How to set 'Run as administrator' on a file using Inno Setup) is widely used.

Unfortunately, this approach does not work in Inno Setup 6.3, as the procedure SetElevationBit encounters an AccessViolation error. The issue is that there is a bug in the TStream.Seek method in this version of Inno Setup.

Upvotes: -2

Views: 96

Answers (1)

Bill_Stewart
Bill_Stewart

Reputation: 24585

Please read Raymond Chen's blog posting: How do I mark a shortcut file as requiring elevation?

Excerpt:

Specifying whether elevation is required is typically something that is the responsibility of the program. This is done by adding a requestedExecutionLevel element to your manifest. ... But if the program you're running doesn't have such a manifest--maybe it's an old program that you don't have any control over--you can create a shortcut to the program and mark the shortcut as requiring elevation.

He provides code for a quick-and-dirty little program that does the work, but then notes at the bottom of the post:

(I fear that most people will read this article and say, "Awesome! My program requires elevation, and this is how I can mark my Start menu shortcut to prompt for elevation. Thanks, Raymond!" These people will have completely ignored the opening paragraph, which explains that that is the wrong thing to do.)

In other words: The recommended practice is to add a manifest to the executable so you don't have to create a shortcut requesting elevation in the first place.

With that said, however, there are cases (such as an old program, as Raymond noted up front) where this is needed. I think the appropriate approach is to use the correct binary interface to update the shortcut's flags rather than directly modifying bits in the file. To meet this need, I wrote an open-source command line tool that does it:

https://github.com/Bill-Stewart/scrunas

I make this tool available for those cases where you can't add a manifest for whatever reason and really do need to mark a shortcut as requesting elevation.

But: If you are able to add a manifest to your program, you should do that instead.

Upvotes: 1

Related Questions