Perl and Windows UAC
While doing some Registry-related things with Perl a couple of weeks ago, I ran into something that took me nearly a day to figure out: Win32::TieRegistry asks for write access to the Registry by default, and under Win7 that requires Administrator privileges. (I kid you not, it took me over a day to figure that out.)
Well, getting what turns out to be called "elevated privileges" from Perl turns out to have been pretty hard - a lot harder than it should have been, for reasons I went into in some detail in a little article about it, but, to cut straight to the chase, I came up with a way to get Perl to restart a script after invoking UAC to gain elevated privileges. It's got some weaknesses that are inherent to the way Windows manages the console, but, well, I present to you Win32::RunAsAdmin. You can use it like this:
use Win32::RunAsAdmin qw(force);
That checks to see whether you're running with elevated privileges already, and if not, it calls the shell to run the same script again with the same arguments, and exits. Obviously, the (few) components of the module are also available separately; check the POD for details. But in all it's about ten lines.
Problem solved. Hope this helps somebody.