Getting your application ware of Vista’s UAC

January 31, 2008

If your application does anything “bad” like writing to program files directory or the local machine part of the registry then its unlikely to run as expected on Vista (dont use the virtual stores).

If your app really needs to write to these forbidden lands your users will need to escalate it to admin privileges via the UAC dialog. Visual Studio 2008 makes this pretty simple, just right click on your solution and select at Add New item, then select Application Manifest File. Open the app.manifest file and change the “requestedExecutionLevel” level to “requireAdministrator”. If, like me, you package the setup.exe bootstrapper and setup.msi in to a self extracting zip, make sure you include the word setup in your exe name. Vista automatically shows the UAC dialog when any executables named *setup*.exe are ran.

Also see http://channel9.msdn.com/Showpost.aspx?postid=334866


OpenID needs more consumer sites

January 29, 2008

After my recent rant regarding single sign on I thought I’d look in to OpenID. For starters I found a couple of useful videos on you tube…

Quick overview…

…and a more in depth beginners lecture…

Ok, if you watched them both your all clued up, well at the least to the same level as me.

I really like the OpenID concept. For me, going to a single site (your OpenID provider) and being able to see all the sites that consume your ID is just as great as only having to remember one password. Unfortunately all the big providers like Yahoo are only providers and don’t yet* consume (i.e allow users to log in to their own services, such as Yahoo mail) OpenIDs themselves. I understand the challenges that integrating OpenID in to existing membership\user systems would cause but if OpenID is going to succeed this is a must. I’m tempted to say sites shouldn’t become OpenID providers if they cant consume OpenID themselves but this seems really short sighted given the exposure OpenID has got from Yahoo becoming a provider.

* I’m aware that Yahoo intend to consume OpenID across their services some time in the future… hopefully sooner than later


Adding application launch option to installations

January 25, 2008

On the whole I really like the setup functionality which comes as with Visual studio. It’s simple and as a consequence is great for creating simple installers. Unfortunately with simplicity comes compromise and often leaves you wanting more. Fortunately thanks to custom classes and marcos you can make Visual studio do most things and their only a google away.

If you want to give users the option of launching the application which was just installed (or configuration dialog / read me) at the end of the installation I suggest use this script by Aaron Stebner.

Original post, http://blogs.msdn.com/astebner/archive/2006/08/12/696833.aspx

1.    Download the sample script and extract the contents to the directory that contains the Visual Studio project you are working on
2.    Open the file EnableLaunchApplication.js in a text editor such as notepad, locate the variable at the top of the file that is set to the value WindowsApplication1.exe, and change it to the name of the EXE that is in your setup that you want to launch when the MSI is done installing
3.    Open the project in Visual Studio
4.    Press F4 to display the Properties window
5.    Click on the name of your setup/deployment project in the Solution Explorer
6.    Click on the PostBuildEvent item in the Properties window to cause a button labeled “…” to appear
7.    Click on the “…” button to display the Post-build Event Command Line dialog
8.    Add the following command line in the Post-build event command line text box:
cscript.exe “$(ProjectDir)EnableLaunchApplication.js” “$(BuiltOuputPath)”
9.    Build your project in Visual Studio

All credit to Aaron, great work.


Reading other app.config files

January 11, 2008

Since VS 2005 its been really easy to read / write app.config properties thanks the to the strong typed Properties.Settings class created for us by Visual Studio. However reading / writing properties of a app.config which belongs to other application isn’t as straight forward. Why would you want to do this anyway? well, perhaps the app.config belongs to a Windows service and you want to give users the ability to alter settings from a configuration application written using windows forms.

The following code requires you to add System.Configuration to your references.

public static void UpdateAppConfigValue(string SettingName, string NewValue)
{
string sConfigFileName = “OwnerApp.exe.config”;
string sSettingsSection = “OwnerApp.Properties.Settings”;
string sSettingName = SettingName;
string sValue = NewValue;

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = sConfigFileName;

Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

ConfigurationSectionGroup grpApp = config.GetSectionGroup(“applicationSettings”);
ClientSettingsSection secPropSet = (ClientSettingsSection)grpApp.Sections[sSettingsSection];

secPropSet.SectionInformation.ForceSave = true;

SettingElement elm = secPropSet.Settings.Get(SettingName);
elm.Value.ValueXml.InnerText = NewValue.Trim();

config.Save();
}

public static string GetAppConfigValue(string SettingName)
{
string sConfigFileName = “OwnerApp.exe.config”;
string sSettingsSection = “OwnerApp.Properties.Settings”;
string sSettingName = SettingName;

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = sConfigFileName;

Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

ConfigurationSectionGroup grpApp = config.GetSectionGroup(“applicationSettings”);
ClientSettingsSection secPropSet = (ClientSettingsSection)grpApp.Sections[sSettingsSection];

secPropSet.SectionInformation.ForceSave = true;

SettingElement elm = secPropSet.Settings.Get(SettingName);

return elm.Value.ValueXml.InnerText.Trim();
}


Elegant solution for dialog conditioning

January 10, 2008

Good dialogs should only show appropriate options. For example Power Management settings should only be available when Power Management is enabled, or when Power Management is selected to be enabled when the dialog is closed.

Data binding provides us with a elegant solution for such dialog conditioning. Simply place all conditional controls (in this case power management settings controls) in to a panel (pnlPMSetting). Data bind the Enabled property of the panel to the Checked property of the enabler control (ckUsePM).

pnlPMSettings.DataBindings.Add(“Enabled”, ckUsePM, “Checked”);


Hello world… again

January 3, 2008

I’m not a fan of new years resolutions (its only the 3rd and I’ve already given up on my Wii Sports exercise plan, at this rate I’ll never get back in them 32’s) however after kicking myself on multiple occasions as a result of not having a suitable soup box I’ve decided I need a blog for 2008.

After some quick research I opted for WordPress, much to my surprise my email address was already registered. It turns out I created an account in May 2006 but never got round to posting anything. This really brings home the requirement for a universal web login (single sign in), having multiple login accounts is simply a nightmare to manage as we move in to Web 2.0 era. Wouldn’t it be great if you could go to a single site and see all the web sites / web apps your email address (or username) is registered to, then remove permissions if you no longer use a particular service. If I remember correctly this was originally planned for Microsoft Passport (now Live Sign in??), hopefully Open ID can pull it off.