Thu, April 26, 2007, 07:38 PM under
Windows |
Vista |
UAC
This is a question I get often:
"How can I determine if User Account Control is on or off via code?"
The answer I always give:
"You are asking the wrong question. Who cares?"
The point being that, regardless of whether the user has turned off UAC or not, your application should still be partitioned and work correctly for both admins and non-admin users. It is irrelevant if UAC is on or off. You should still display the shields, you should still gracefully fail if the user is not an admin (same as you would if the elevation prompt came up and the user cancelled, same as you should if you were running on XP). The academic answer to the original question is that you can read it from the registry (much like the built-in Security Centre does). Since there is no genuine requirement to know this stuff from code, there is no API for it.
So the only question to answer programmatically is how to know if the user has admin rights. I have shown how to do this before but here goes again:
// using System.Security.Principle;
private bool IsAdmin()
{
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal p = new WindowsPrincipal(id);
return p.IsInRole("Administrators");
}
I have
read blogs where others get further information regarding elevation about the user's account by pinvoking native APIs, but again, I remain totally unconvinced about that need. Your app shouldn't care about anything else: all that matters is if the user has admin rights at the moment your admin code is about to execute, nothing else.
If you disagree and think you have a genuine reason for knowing more than what I describe above, then please post your scenario to the relevant
forum linked to from here.
Thu, April 26, 2007, 04:09 AM under
Orcas |
VisualStudio
Recently I repaved my Toshiba M5 starting from scratch (format, Vista RTM, join domain etc). The way this works for me is that I have a secondary drive in the laptop with all my data plus apps (multiple msi files, setup.exe files, iso images etc). I install the OS on the main drive and then continue to install the other applications from the 2nd drive. Looking at my instructions (I've written a simple installation todo.txt file that reminds me of what to do), I used to install the following for my mobile development needs: VS2005, SP1, SP1 Update for Vista, Latest NETCF SP, WM5 PPC SDK, WM5 SP SDK, DE v2. I am sure this isn't the story for device development only, but that every developer has their own set of things they install on top of VS e.g. WF Extensions, WPF/WCF extensions, VSTO SE, AJAX, MOSS SDK etc - overall a dozen or more separate installation packages (separate to install, separate to maintain/keep).
With the advent of
Orcas Beta 1, I decided to ditch VS2005 completely and only install Orcas as my sole dev environment (btw, without
multitargeting this decision would not be possible). It is only then that I truly realised that I do not need *any* of the above extras/extensions/SDKs since they *all* ship in the box as part of the single installation! :-)
The side benefit of this is that, previously if you had no interest in some technology (e.g.
Office development or
web development or
device development) you probably wouldn't bother installing something separate, but now the story is different: it is just there so you can have a quick play with it whenever you want and ignore it thereafter if you still don't fancy it.
What will
YOU install the next time you repave your machine:
VS2005 side-by-side with Orcas or
just Orcas?