UAC Standalone Subroutine
Here's a single subroutine you call first thing in your script.
It checks the operating system and administrative status and
re-launches the wscript as needed. If a UAC or RUNAS prompt isn't
needed, the subroutine exits without doing anything. If a prompt is
needed, a separate temporary script is generated in the root, control
is passed to that script, and the original script shuts down. The
temporary script then relaunches the original script with the "runas"
argument to the Shell.Application's "ShellExecute" method. An effort is
made to try to pass all script arguments to the re-launched
script.
UAC Multiple Subroutines
Here's a collection of subroutines that does the same thing as
the above script. The difference is that the functions are all broken
out. There's a function to determine the operating system, a function
to determine the user name, another to determine if a given user is an
administrator, one to determine if a UAC prompt is really needed, and
even a few bonus functions to determine if WMI is installed and if
Windows Scripting is working correctly (you'd be surprised!). Oh yes...
There's also a function to generate the UAC prompt.