Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VS Setup Projects and Vista "Run as Administrator"

44 views
Skip to first unread message

Eric Johnson

unread,
Nov 1, 2007, 8:50:48 AM11/1/07
to
I have a VS2005 setup project for installing my C# application.
Nothing fancy, just copies some files to Program Files and creates Start
Menu shortcuts.

On Windows Vista, the "Run as Administrator" is missing from the context
menu when I right-click my shortcuts. I need that capability, what
makes that disappear? How can I get it to appear?

Thanks,
Eric

David Hearn

unread,
Nov 1, 2007, 9:13:13 AM11/1/07
to

MSI files are always run as Administrator (well, they always elevate
midway through) so they don't have "Run as administrator" on the context
menu.

D

Eric Johnson

unread,
Nov 1, 2007, 9:22:05 AM11/1/07
to
Yes, but I'm referring to the shortcuts my setup creates to my application.

Start...Programs...My App -> c:\program files\blah\blah.exe

The "My App" shortcut doesn't have Run As Administrator in the context menu.

David Hearn

unread,
Nov 1, 2007, 10:38:01 AM11/1/07
to
Sorry, I mis-read your question.

I believe shortcuts don't support Run As Administrator - only the actual
.exe itself. I've never seen Run As Administrator on any shortcut I've
tried.

If you want to always run the target of the shortcut as Administrator
then set that option on the .exe itself. But I don't know of a way of
doing that on an at execution option basis. It's either always As
Admin, or not at all.

If you want to get the app to always run as Administrator without having
to manually set the option on the .exe, then I believe you need to
create a manifest for the .exe which states it must run as Administrator.

Hope that helps,

David

Eric Johnson

unread,
Nov 1, 2007, 11:02:09 AM11/1/07
to
Actually, most regular shortcuts do have the Run as Administrator. I
can manually create a shortcut to my app (and all apps I think) and it
appears just fine. It has something to do with how the VS Setups create
the shortcuts, but I just don't know what to do about it.

In my case, I don't want the app to be run as administrator each and
every time. Just the first time they run it so some other features can
be installed and configured.

David Lowndes

unread,
Nov 1, 2007, 1:25:40 PM11/1/07
to
>Actually, most regular shortcuts do have the Run as Administrator. I
>can manually create a shortcut to my app (and all apps I think) and it
>appears just fine. It has something to do with how the VS Setups create
>the shortcuts, but I just don't know what to do about it.
>
>In my case, I don't want the app to be run as administrator each and
>every time. Just the first time they run it so some other features can
>be installed and configured.

It might be best to re-think your strategy - you're flying into the
wind.

One possible solution may be to have your application start another
instance of itself in that initial situation (then close the initial
instance) by using ShellExecute with the RunAs verb. See
http://blogs.msdn.com/vistacompatteam/archive/2006/09/25/771232.aspx

Dave

Eric Johnson

unread,
Nov 1, 2007, 2:18:37 PM11/1/07
to
Please explain how having Run as Administrator on my start menu shortcut
is "flying into the wind"? If I can just get a "regular" shortcut
created like every other app on my start menu (Office excluded). If no
other app's shortcut had the option I might consider my request absurd,
but this is something that the VS install seems to be screwing up.

Thank you for a suggested workaround, if push comes to shove I will keep
it in mind. Although I think a better alternative would be me
investigating the WiX installer.

That said, does anyone know what the VS installer is doing when it is
creating these shortcuts?

Richard

unread,
Nov 1, 2007, 2:41:11 PM11/1/07
to
[Please do not mail me a copy of your followup]

Eric Johnson <e...@ejinnovations.com> spake the secret code
<IYjWi.53667$g82....@fe07.news.easynews.com> thusly:

>I have a VS2005 setup project for installing my C# application.

>[...]

I believe what you're seeing is a consequence of the way VS tries to
hide install details from you in order to "help" you.

At this point, I've given up on improving VS.NET deployment projects;
all of the critical bugs I've filed have been ignored and the thing is
just too slow and buggy for anything besides an extremely simple
install.

Instead, I now routinely recommend that people use WiX to build their
setups. Its free, open source, has more features, better quality and
better build performance.

<http://wix.sourceforge.net>
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>

David Lowndes

unread,
Nov 1, 2007, 2:52:41 PM11/1/07
to
>Please explain how having Run as Administrator on my start menu shortcut
>is "flying into the wind"?

I wasn't referring to that aspect - I also found that a deficiency in
the VS installer. I was referring to your requirement to have the
application run *sometime* as Administrator. It's generally
recommended have any admin functionality in a separate program that
you would explicitly mark in the manifest as requiring admin. That way
the elevation prompt would happen automatically.

Dave

Eric Johnson

unread,
Nov 1, 2007, 2:57:43 PM11/1/07
to
Thanks, Richard.

I've fought it off and on as well, and recently spent a lot of time on
the setup process of my application. I can't believe a shortcut is
what's keeping me from calling these improvements complete.

I'm going to try one thing to get around this - creating a custom action
that calls the win32 api to create the shortcut for me. If that doesn't
work, WiX is where I'll head.

It's said they provided such a crippled solution for installers.

Thanks again,
Eric

Eric Johnson

unread,
Nov 1, 2007, 3:05:47 PM11/1/07
to
I see. For the time being, I might mark the manifest as
highestAvailable. This way, only actual administrators would be
prompted all the time.

Eric

Richard

unread,
Nov 1, 2007, 9:41:57 PM11/1/07
to
[Please do not mail me a copy of your followup]

Eric Johnson <e...@ejinnovations.com> spake the secret code

<HkpWi.360350$6L.1...@fe03.news.easynews.com> thusly:

>It's said they provided such a crippled solution for installers.

I could live with the simplified feature set if it wasn't ridiculously
slow and buggy.

David Hearn

unread,
Nov 2, 2007, 5:16:11 AM11/2/07
to
Actually, what I've found is that many shortcuts that get created via
installers (ie. appear in the Start Menu) - including Office 2007
shortcuts - don't have Run As Administrator. However, if I go to an
.exe and right click, selecting "Create shortcut", the resulting
shortcut properties has an additional Compatibility tab, and also has
the Run As Admin context menu.

Strangely, my Firefox shortcut on Start Menu *does* have
Compatibility/Run As Admin. Maybe a different installer was used?

Doing a quick search though found:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1439749&SiteID=1

Which seems to show how to use an API to alter the shortcut settings.

Hopefully that might help,

David

David Hearn

unread,
Nov 2, 2007, 5:23:32 AM11/2/07
to
Additionally, MS say <http://support.microsoft.com/kb/922708>:

"For some program icons, the Run as administrator option is not
available on the shortcut menu. For these program icons, follow these steps:
1. Right-click the icon that you use to run the program, and then click
Properties. On the Shortcut tab, the Target box contains the location
and the name of the program file.
2. Open the folder that contains the program file.
3. Right-click the program file, and then click Run as administrator.
User Account Control permission If you are prompted for an administrator
password or for a confirmation, type the password, or click Continue."

and

"The Compatibility tab is not available for some program icons. For
these program icons, follow these steps:
1. Right-click the icon that you use to run the program, and then click
Properties. On the Shortcut tab, the Target box contains the location
and the name of the program file.
2. Open the folder that contains the program file.
3. Right-click the program file, and then click Properties.
4. On the Compatibility tab, click to select the Run this program as an
administrator check box, and then click OK."

Not exactly much of a solution....

D

David Hearn

unread,
Nov 2, 2007, 5:26:39 AM11/2/07
to

Sorry for all the replies, I've possibly found a far simpler solution:

<http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1482049&SiteID=1>

"I'm a Windows Installer novice Smile with the same problem. I found
that the solution is straight-forward for a standard MSI installation.
The secret is changing the Target value for your app in the Shortcut
table. This causes Windows Installer to create a standard shortcut, the
only way to get the Run as Administrator context option.

As an example:

1) Examine your File table to see what the key is for the program you
want to give a standard shortcut. Let's say the key is "myprog.exe".

2) Open the Shortcut table for your install and locate the shortcut
entry you want to change.

3) Replace the Target value with "[#myprog.exe]". The brackets and
pound sign are a Formatted string that tells WI to create a standard
shortcut to the file.

It took me several days to track this down. I hope this post helps
save others some of that grief."

Someone reported that it worked for them - hope it does for you.

David

Eric Johnson

unread,
Nov 2, 2007, 8:42:55 AM11/2/07
to
Thanks for tracking that info down, I hadn't run across that article before.

Last night I ended up creating a custom action and creating the shortcut
myself with the win32 api.

Thanks again,
Eric

Eric Johnson

unread,
Nov 2, 2007, 8:46:57 AM11/2/07
to
I did run across that but since I have automated builds, the last thing
I wanted was to have to go in and manually make a change. Obviously
that doesn't mean that it couldn't be scripted/coded, but I hadn't gone
down that route yet.

Thanks again David,
Eric

Richard

unread,
Nov 2, 2007, 12:00:27 PM11/2/07
to
[Please do not mail me a copy of your followup]

David Hearn <david...@newsgroup.nospam> spake the secret code
<eOaA6JTH...@TK2MSFTNGP03.phx.gbl> thusly:

>Sorry for all the replies, I've possibly found a far simpler solution:
>
><http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1482049&SiteID=1>

As I mentioned earlier, this is all because VS.NET deployment projects
hide details of the install from you, so you don't get to choose
whether or not your shortcuts are 'advertised'. Advertised shortcuts
don't get the Run as... but regular shortcuts do.

You can do either from Windows Installer, but not from VS.NET.

Please, just forget about VS.NET deployment projects and use WiX. WiX
will let you do what you want and there is a tool to decompile your
existing MSI project into a WiX source file (which is just an XML file
that you can edit in any text editor). Then you will have something
you can easily edit as needed to do *anything* Windows Installer will
let you do, such as non-advertised shortcuts. It will be more
reliable and faster to build and modify than VS.NET deployment
projects.

<http://wix.sourceforge.net>

Richard

unread,
Nov 2, 2007, 12:02:08 PM11/2/07
to
[Please do not mail me a copy of your followup]

Eric Johnson <e...@ejinnovations.com> spake the secret code
<iXEWi.425494$TR1....@fe06.news.easynews.com> thusly:

>Last night I ended up creating a custom action and creating the shortcut
>myself with the win32 api.

This is a fragile solution, particularly since you don't need a custom
action to create non-advertised shortcuts!

Now you will need to write a custom action that removes the shortcut
on uninstall. You will also need to write a separate custom action
that removes the shortcut on rollback. You've also just increased
your test matrix.

Switch to WiX instead and you don't need the custom action.

Eric Johnson

unread,
Nov 2, 2007, 1:01:42 PM11/2/07
to
Yeah, I've got those actions in there right now. It's obviously less
than ideal, and I will be looking at changing the installer for the
following release. I just need to get this release out the door ASAP.
0 new messages