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]
Comments
Fri, 01.08.2008 09:01
อยากมีความรู้เยอะๆอ่ะ แนะนำบ้า งนะค่ะ
Mon, 21.07.2008 15:33
สาขาศาลายมงเช้าา เปิดทุกวันตั้ งแต่ 9 โมงเช้า - 4 ทุ่ม ทุกวัน
Mon, 23.06.2008 00:15
good idea
Fri, 20.06.2008 00:50
โอ้ ปั้นหมีโหดมั่งๆ อิ อิ