Include the following three routines in your script:
Scripting and the UAC
When writing scripts for use in Vista, you??™ve always got to think about security
and the User Access Control (UAC) feature, both discussed in Chapter 8.
For instance, with Vista set to its defaults, any applications you launch with
a script will be run under the standard (limited) user account. If your script
needs to open applications and issue commands (such as the Registry functions
covered in the next section) as the administrator, then your script needs
to be run under the administrator account. As explained in Chapter 8, you
can set wscript.exe to always run in administrator mode, but this would cause
all scripts to run under the administrator account, and would open up a nasty
vulnerability on your PC. So, what to do?
Unfortunately, you can??™t right-click a .vbs file and select Run as administrator,
as you can with executables (.exe files). But you can get around this limitation
in a few different ways.
First, you can write a one-line batch file (discussed later in this chapter) that
does nothing more than launch your script. Then, to run the script in administrator
mode, right-click the batch file and select Run as administrator.
Or, to run all your scripts in administrator mode without making your system
vulnerable, make a copy of the wscript.exe file called something like
wscript_admin.exe. Right-click the wscript_admin.exe file, select Properties,
choose the Compatibility tab, and then turn on the Run this program as an
administrator option.
Pages:
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730