Using UAC with C# – Part 3
After a long period since I wrote part 2 of this article I decided to add some extra information. There is one thing that was missed by the previous two articles: the design of UAC enabled applications.
If you use Windows Vista/7 then you know that buttons and links which elevate privileges are preceded by a shield icon. This is the way Microsoft decided to inform the user about the effect of clicking that control.
The first idea that might pop up is the reinvention of the wheel (or shield). In other words you could draw the shield on a button. This is OK except that:
- Is not easy
- Will require you to recompile the interface if Microsoft decides to change the icon
- You need the icon in many sizes 16×16, 24×24, 32×32, etc. (extract it from MS’ DLLs)
- Will create a lot of overhead with layout (position icon relative to text size/position)
The second method is easier, safer and recommended by MS. All you need to do is send a specific message (BCM_SETSHIELD) to the button if the user has limited privileges and pressing that button will trigger the UAC window. Actually there is a second, tricky, thing that must be done: the style of the button must be “System” (in C# “System.Windows.FlatStyle.System”). Without this you will not be able to see the shield.
The code provided in part 1 of this article will be modified in order to display the shield on the two buttons. Moreover, the shield will be displayed only when the user runs under an account with limited privileges or non-elevated administrator.

In order to display the shield one needs to send the BCM_SETSHIELD (=0×0000160C) message to the button. This can be done by using the SendMessage function from user32.dll. This article will not cover what is and how to use SendMessage, if you need more information about it follow the previous link.
To set the shield of the “Elevate this application” button one needs to send the message in the following way:
SendMessage(btnElevate.Handle, BCM_SETSHIELD, 0, 1); |
The first parameter is the handle of the button, the second one is the message, the third one is not used and must be ‘0′ and the last argument must be non-zero in order to draw the shield, zero otherwise.
If you try this it will not work :) Remember the ‘tricky’ thing told before? This is the full code to display the shield for btnElevate:
btnElevate.FlatStyle = FlatStyle.System; SendMessage(btnElevate.Handle, BCM_SETSHIELD, 0, 1); |
There is only one thing that must be done in order to work properly. Remove the shield if the user has elevated privileges. I don’t know if this is against MS’ recommendation but in my opinion one must not be shown information that cannot be used in that context; in our case don’t show the elevate shield if there is nothing to elevate.
Part 1 described how to check if a user has full rights. Now we are just using that boolean variable:
if (!hasAdministrativeRight) SetUACShields(); |
Where SetUACShields will send the message to all buttons that require the shield drawn.
The full updated code from Part 1:
UAC Code 3 (10.13 KB)
1, 2, 3, 7!

Today is a big day for Windows fans. The final milestone in Windows 7 development process has been reached and the new operating system is general available.
Just two years passed since the release of Vista and many say that Windows 7 should be just a “super-service pack” for Vista.
If you are not a MS Partner and you don’t have a MSDN/TechNet Subscription then this is the first time you can get Windows 7 non-trial. Many shops already started to sale and deliver copies of W7 – got few mail in the morning with special offers.
The prices on Amazon are:
- Windows 7 Home Premium (Retail/Upgrade): $199.99/$119.99
- Windows 7 Professional (Retail/Upgrade): $299.99/$199.99
- Windows 7 Ultimate (Retail/Upgrade): $319.99/$219.99
And now two funny things: on Amazon you have “2 Used and new” copies of Windows 7. I wonder who has a used copy of W7 that has just been released :)
The image on the right I found it on Larry Osterman’s blog.
Office 2010 Web Apps
Most of you know Google Docs (GD) - the web-based word processor, spreadsheet, presentation, and form application offered by Google. Probably in the attempt to remove GD’s supremacy and to promote their new Office 2010, Microsoft is preparing a free online version of Office called Office Web Apps.
For the Technical Preview four application are available: Excel, PowerPoint, Word and OneNote. Each of them tries to reproduce the aspect and the functionally of their offline big brother. For Office 2007 users, the interface is well known. In the top side we have a Ribbon bar, the middle part is dominated by the working area and to bottom is reserved for an optional status bar.
In order to use Office Live Apps you need to have a Live ID and a Skydrive account. All these applications integrate with Skydrive and this is a curious fact because I would expect to be part of Office Live [very strange decision!].
The interaction with the live apps is not really fluid because it has a delay, especially in Excel, when you work with formulas – it takes 3-4 seconds to see the result. I understand Microsoft’s wish for adoption and interoperability with any browser without any addon, of the new product, but I think that a Silverlight interface would improve the usability or at least some drag/drop support and a right click menu.
Excel Live
Spreadsheets – this is Excel all about. The little brother of the offline version is, for the moment, limited to some basic spreadsheet operations. The are no more and no less then 3 sheets [does anyone know how to add/remove them?] on which you can put your data.
The simple tools available are: text format (color, font, size) and cell format (color, text alignment, data type). There is support for part of the formulas in Excel and one can use cell references to add dynamic data. There is some support for external data sources but it seems that data can only be refreshed if already exists – one cannot add/modify a data source.
Unfortunately there is no support for locked sheets, hidden sheets and data validation. If you try to open an uploaded document containing some of the previous you will get and error message for edit.
Excel Web Apps gets another minus because there is no support for diagrams/charts. It would be nice to have at least support for charts in a new sheet. Maybe in the next version?
I am thinking to migrate my expenses Excel document in Skydrive (Office Live Apps) even though it is quite limited.
Tip #5: Get 25GB Online Free Storage
Do you want 25 GB of free storage that can be accessed from anywhere you have Internet connection?
Microsoft is offering 25 GB free online storage through SkyDrive. The drawback of this service is that you can only access files through a browser and if you want drag/drop facilities you must use Internet Explorer.
Gladinet is developing a tool for mapping online drives as network drives. Using it you can map SkyDrive (and other services like GoogleDocs, Amazon S3, etc) in Windows Explorer. It is not the fastest or easy most solution but there is no other to map SkyDrive.
After you install Gladinet Cloud Desktop and configure it (it has an easy to use wizard) you get one more drive in My Computer that will contain subfolders for each online service you use. You can move files there just like they were local. Must mention that the sync is not instant. There is a tasks queue so each file is put in this queue and uploaded only after the previous has finished. Each operation works like this so you might no see online changes immediately.
Gladinet Cloud Desktop is available in two versions: free and pro. The free version has a file limit of 1000 files/batch which, I think, should be enough for most users.
Register for SkyDrive and download Gladinet Cloud Desktop.
Windows 7 Enterprise FREE Trial
It’s been a while for my last post. I was busy moving to another country – will explain this in another post.
Microsoft has announced the download availability of Windows 7 Enterprise for trial inside your environment.
The Windows 7 Enterprise trial is designed specifically for IT Professionals, so that you can test your software and hardware on a final version of the product. In addition, it provides the opportunity for you to become more familiar with the key improvements over previous versions of the Windows operating system, and experience firsthand how Windows 7 can make your PC environment more productive, secure, and manageable.
There is a time limit for downloading this version so better hurry. Access this site. However, if you are a MS Partner or Technet/MSDN subscriber you should check your software subscription page because you can access the non-trial version.
Tip #3: Shared OneNote notebooks with Live Mesh
OneNote allows users to create shared notebooks by using a shared folder or a SharePoint repository. When two persons who want to share a notebook are in different countries then a shared folder is not a too feasible solution. A SharePoint repository can be created for free on Office Small Business but you have only 50 MB for storage and you need at least basic SharePoint knowledge.
As you might already know, Live Mesh allows one to sync files across multiple computers. A big advantage is the Live Desktop - a 5000 MB online storage location that can be used for storage. When computers involved in the sync are not simultaneously online, the files are synced with the Live Desktop and, when the computers are back online, the files will be synced.
The sharing with Live Mesh works like this: add notebooks’ files on Mesh and they can sync across computers. When a notebook is updated, if you are online the change will be sent/received to/from the Live Desktop.
Tip 2: #if
This is a C# tip
When the C# compiler encounters an #if directive, followed eventually by an #endif directive, it will compile the code between the directives only if the specified symbol is defined. Unlike C and C++, you cannot assign a numeric value to a symbol; the #if statement in C# is Boolean and only tests whether the symbol has been defined or not.
A predefined (by default) symbol on the “Debug” build configuration is DEBUG. Using this symbol you can define code that will be compiled only in Debug; for example, a debug window will be shown only when needed.
using System; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { #if DEBUG Console.WriteLine("Debugging information"); #endif Console.WriteLine("Code that always executes"); } } } |
The code above will print “Debugging information” and “Code that always executes” when build on Debug and will display only “Code that always executes” when build on another configuration.
You can suppress the definition of the DEBUG symbol from the project properties or by removing the DEBUG from the build argument “/define:DEBUG”. Also, you can define your own symbols in order to accommodate your needs.
Define as many build configurations and symbols you need but don’t abuse this feature!
Windows 7 RTM Date Announced
Yesterday, Brandon LeBlanc, announced on the Windows 7 Team Blog, the official release dates for Windows 7 RTM (Release To Manufacturer).
Depending on who you are you will be able to get W7 RTM sooner or later:
- Partners & OEMs
- ISV (Independent Software Vendor) and IHV (Independent Hardware Vendor) Partners will be able to download Windows 7 RTM from Microsoft Connect or MSDN on August 6th.
- Microsoft Partner Program Gold/Certified Members will be able to download Windows 7 RTM in English through the Microsoft Partner Network (MPN) Portal on August 16th.
- Microsoft Action Pack Subscribers will be about to download Windows 7 RTM in English starting August 23rd.
- OEMs will receive Windows 7 RTM software images beginning approximately 2 days after we officially RTM.
- Business Customers
- Volume License (VL) customer with an existing Software Assurance (SA) license you will be able to download Windows 7 RTM in English starting August 7th via the Volume License Service Center (VLSC).
- Volume License customers without a SA license will be able to purchase Windows 7 through Volume Licensing on September 1st.
- IT Professionals with TechNet Subscriptions will be able to download Windows 7 RTM in English on August 6th.
- Developers with MSDN Subscriptions will be able to download Windows 7 RTM in English on August 6th.
- Beta Testers & Enthusiast will not receive a free copy of W7 and will be able to purchase it after the official release.
- For Consumers: will be in retail stores and shipping on new PCs starting October 22nd.
New Windows Azure Tools (July 2009)
After releasing the pricing scheme and the business model, Microsoft announced a new set of tools for Windows Azure.
Windows Azure Tools for Microsoft Visual Studio extend Visual Studio 2008 and Visual Studio 2010 Beta 1 to enable the creation, building, debugging, running and packaging of scalable web applications and services on Windows Azure.
The most interesting feature is probably the support for multiple roles. Now one can deploy many web/worker roles.
What’s new in the Windows Azure SDK?
- The Windows Azure SDK supports developing and deploying services containing multiple web and worker roles. A service must include at least one role, of either type, and may include zero or more web roles, and zero or more worker roles.
- The new PowershellRole sample hosts the Powershell runtime within a Windows Azure role. It demonstrates a simple remote console web role as well as a worker role whose implementation is a Powershell script. The host also includes the CloudDrive sample snap-in to provide access to Windows Azure Storage from script.
What’s new in Windows Azure Tools for Visual Studio
- New project creation dialog
- Support for developing and deploying services containing multiple web and worker roles. A service may contain zero or more web roles and zero or more worker roles with a minimum of one role of either type.
- Ability to associate any ASP.NET Web Application project in a Cloud Service solution as a Web Role
- Support for building Cloud Services from TFS Build
- Enhanced robustness and stability
The new CTP Release can be downloaded from this link.
What is Windows Azure?
Just found a nice video describing what Windows Azure is.
I already explained what Azure is a previous post, Windows Azure Application Architecture, but I find this video funny and interesting.
PS: Sorry but this post is not XHTML valid :( I haven’t managed to embed the object in a proper way. Does anyone have a suggestion of how to correct this?



