When you are on Microsoft Windows Vista Platform. It is hard to create a script that use privilage command. One way is by use the command "Runas" as follow
C:\> Runas /user:Administrator cmd
However, the above command will ask for Administrator password before continue next process. It is not good to create automate script by using above command. After I googling for several week, I found the way to create batch script and it can use privilage command, no administrator password needs, but it will show UAC dialogbox ask to confirm an operation.
Type a text as follow in elevate.js
---------------------------------------------------
// elevate.js -- runs target command line elevated
if (WScript.Arguments.Length >= 1) {
Application = WScript.Arguments(0);
Arguments = "";
for (Index = 1; Index < WScript.Arguments.Length; Index += 1) {
if (Index > 1) {
Arguments += " ";
}
Arguments += WScript.Arguments(Index);
}
new ActiveXObject("Shell.Application").ShellExecute(Application, Arguments, "", "runas");
} else {
WScript.Echo("Usage:");
WScript.Echo("elevate Application Arguments");
}---------------------------------------------------
Then use it as below
- elevate cmd.exe "/t:fc /k cd /d c:\ && title ** Admin console ** "
- elevate mybatchscript.bat
- elevate route add ....... bra bra bra..
Hope this entry help all of you who want to create administrator script on vista.
Reference:
- MSDN Blog [Ref]
- Another way (By VBSCRIPT) [Ref]
- Use joeware utility names cpua (Popular in a lot of webboard) [Ref]
- Review and tools for administrator (Runas) [Ref]
- Microsoft Script Center [Ref]




Wed, 31.12.2008 13:42
ขับรถจากแยกสามย่านเลี้ยวเข้าถ. พญาไทเลี้ยวซ้ายเข้าทางจุฬาซ.42 แล้วก้อเลี้ยวซ้ายซอยแรกอยู่ด้ านซ้ายมือค่ะ