Posted By: Daniel Moth | Aug 16th, 2007 @ 6:22 PM | 15,828 Views | 11 Comments

Author: Hi, I am Daniel Moth Smiley

Introduction:
User Account Control is the top compatibility hurdle for some applications moving to Windows Vista. It is relatively easy to comply with some elements of UAC (e.g. embedding a manifest in your app) and with Visual Studio 2008 it is even easier as I show in this video. Relevant blog posts of mine are here and here.

Video download:
Click on the image to play the video (from a streaming file). If you'd prefer to download the wmv packaged in a zip file, you may do so here.

Rating:
2
0
VBCoder
VBCoder
Waleed El-Badry
In my humble opinion, I think Visual Basic Team gave me a big relief as the UAC issue raised with Vista made development really hard. Thanks again for overcoming this dilemma.
I rather thought that the manifest was just another resource -- in which case, why not edit it through the normal resource editing mechanisms instead of via Yet Another Weird Action?

And why is this so late?  Did the VS2005 team really not know that Vista was coming?

And why does the "UAC Options" button in VB.NET mode actually create a file?  Isn't that just about the last action that anyone would expect given the labeling on the button?

Lastly, this video is grossly mistitled.  It's not about making UAC aware apps - the app knows nothing about UAC except for a "magic string" in the manifest.  It would be nice to know if an app can detect that it's elevated, or handle the user not running it.  But since these apps aren't actually UAC aware at all, that's not possible.
evildictaitor
evildictaitor
if( !succeed( try() ) ) { while(true) try(); }
rsclient wrote:
It would be nice to know if an app can detect that it's elevated, or handle the user not running it. 


public static class UAC {
  public static bool AmElevated(){
    return new WindowsPrincipal(WindowsIdentity.GetCurrent())
       .IsInRole(WindowsBuiltInRole.Administrator);
  }
  public static void Elevate(){
    if(AmElevated()) return;
    ShellExecute(IntPtr.Zero, "runas\0",
       Application.ExecutablePath + "\0", "\0", "\0", 1);
  }
}

...

public class Program {
  public static void Main(){
    if(!UAC.AmElevated()){
      MessageBox.Show("I'm not elevated, asking you to elevate...");
      UAC.Elevate();
    }else{
      MessageBox.Show("I'm elevated, yays!");
    }
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
  }
}
Brice It
Brice It
Email Brice
You showed us how to create an embedded manifest in VS 2005 but what about embedding one in VS 2005 Express Edition?

There is no manifest template there for that.

My guess is that we should just copy a manifest file from a sample VS 2008 app into a VS 2005 project file. Is this correct?

Since both are running on variations of the 2.0 framework it shouldn't be a problem. Is this correct or is there another more appropriate way in which to create an embedded manifest in VS 2005 Express Edition?
 
 
 
Normal 0 false false false EN-AU X-NONE X-NONE MicrosoftInternetExplorer4
 
 
 
 
/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}

Hi Daniel,

 

There is an issue with auto generating UAC manifest with Visual Studio 2008.  It’s hard codes the version and name as follows:

<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />

 

This is reported to MS but the resolution was not clear:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=290160

 

What "setting on the project" updates this version? Please let me know.  I really need a dynamic way to updating the assemblyIdentity  settings as manually updating it for every build is tedious.

 

Thanks for your assistance with this.

Microsoft Communities