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)
Happy New Year

See you in the next year…
Tip #8: Make Firefox Better
What I want from a browser
- To show the pages correctly
- To show as much as possible from a page (to remove the need of scrolling)
- To provide me with an easy way of accessing pages.
What I don’t like at Firefox
- The search bar is superfluous. I really like what Chrome is doing (and the latest version of Opera?): use the address bar as search bar.
- There is no ad blocker
- There is a lot of wasted space: bookmarks toolbar, menu bar (just think how often you use the top menu), big icons
After a few tweaks I got a browser looking like the one in the picture below that satisfies almost all my needs.
Tweaks applied and how/why to use them
Part of my plan: Books
I decided to read books (real books!) and many of them. For those (geeks) that don’t know what books are I will remind that books were used before the computers age, by people (!), to store and transmit high quantities of information. :-)
Today books are used to add extra height to different objects ranging from computers and laps to … babies. Books can be also found on shelves. If you find yourself between many shelves with many books it means you are in a library or a book store.
OK, funny enough. I tried to gather, from different sources, the high rated titles (tech and non-tech geeky books). The reading process will take me a few months (years maybe) but it worth.
It is obvious that one cannot enjoy all the books people recommend. Many times I found horrible a book rated by many with five stars. I am sure that from the list of books I want to read at least 10% will be abandoned after the first few pages. Some books just don’t have that… sparkle… that makes you want to continue the lecture.
Each book will get one of the following ratings:
- “Must read” (these books will get on the Books page)
- “Good book”
- “Mediocre”
- “Bad book”
Currently I am reading the first book in the list and seems to be a good one. Here goes “The List” in random order.
Did you read one of these books? Help me prioritize the list by telling your opinion about that book.
To visualize or not to visualize
VSImageVisualizer is one of my free open-source projects. Basically, it is debug visualizer for images for Visual Studio 2008 that allows developers to inspect the graphical representation of Image objects while in Debug mode.
Check the project page for more info.
11-11-11-11 Contest Winners
The winners of the contest are:
1st place (HandyBackup Professional): Timotei Dolean
2nd place (HandyBackup Standard): tisi, Ursul
Winners: please check your e-mail Inbox and Junk folder.
11-11-11-11 Contest
First Place
|
2 x Second Place
|
The rules of the contest are simple:
- Write here (as a comment) or on another site (with link to this post) the most unusual way in which you could lose your data.
- The text must be written in English.
Contest period:
- Starts on October 27th, 2009 at 11:11 AM GMT
- Ends on November 11th, 2009 at 11:11 AM GMT
Why 11-11-11-11?
- Because the contest ends on 11/11 at 11:11.
Prizes:
- Handy Backup Professional license
- 2 x Handy Backup Standard license
Winning conditions:
- The best 3 texts win.
Winners will be announced on November 12th.
Reviews of Handy Backup:
Remarks:
- If you post as comment make sure you enter a valid e-mail address so I can contact you in case of winning.
- If you post on another site make sure there are some contact details there.
Handy Backup Review
The worst thing can happen is to loose all you the pictures you made in the last 2 years or all the customer information you gathered in the last 5 days. These kind of scenarios can happen to anyone and unless you create a duplicate of your data (a backup) you cannot recover it. There are many ways in which data can be accidentally destroyed:
- Hardware failure
- Software failure
- Accidents (fire, water, earth quake)
- Theft
Handy Backup from Novosoft is a solution that can help in this unfortunate situations (if is used prior to those events :) ). Unlike most other backup software out there, Handy Backup doesn’t treat your data like faceless chunks of memory. It features a complete, extensible plug-in-based system and a variety of plug-ins designed to back up settings, playlists, tweaks and preferences. New plugins care be created with basic XML knowledge.
Tip #7: VMWare Unity View
I just found a really cool feature in VMWare Workstation 6.5.3. It is called “Unity View” and basically allows windows from a virtual machine to appear as windows in the host machine.
In the example pictures you can see that I have a host running Windows 7, a unity windows from a Windows Xp guest and two windows from a Fedora guest (Picture 1). The best part is that you can actually see those windows in your taskbar and manipulate them as regular windows – you can use the Aero switch to switch between applications (Picture 2 & 3). However I found a minor bug, the Aero Peek feature in Windows 7 is not working with the unity windows.
Least but not last you get access to the start menu of the guests (Picture 4).
Spell check MSDN fail
Check out this fail:
Don’t worry if you can’t understand it. Is just that you are not geek enough. :)

























