Dec 14
Technical

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:

  1. MSDN Blog [Ref]
  2. Another way (By VBSCRIPT) [Ref]
  3. Use joeware utility names cpua (Popular in a lot of webboard) [Ref]
  4. Review and tools for administrator (Runas) [Ref]
  5. Microsoft Script Center [Ref]

Posted by Scalopus+

Defined tags for this entry: , , , , ,

Last modified on 2007-12-15 04:47