I am trying to write a script which includes disk defragmentation as one of its steps. defrag needs administrative rights to work. I tried to use runas /user:Administrator, but it always asked me for password (even though there isn't one set).

The script needs to run unattended for a long time, and it needs to be started from standard user account (it is actually being run by cygwin), so I'd like to get rid of that prompt. Is this possible?

Thanks,

link|improve this question

45% accept rate
feedback

2 Answers

Right click cmd.exe and "Run as administrator". Call the script from inside the command line. The command line prompt's window title will be: Administrator: C:\Windows\System32\cmd.exe

link|improve this answer
Most of that script don't need admin rights, so I'd like to avoid running full script with full privileges. – liori Jun 28 '10 at 20:33
@liori Yet defrag NEEDS to be run as administrator, there's no other way if you want to avoid retyping your password every time. – BloodPhilia Jun 28 '10 at 20:35
On Linux I can give user rights to run specific command as another user using sudo. Microsoft says Windows is superior to Linux, so there must be a way to do that :-) – liori Jun 28 '10 at 20:41
I assumed there is something that doesn't require installing 3rd party software, like in a typical Linux installation... – liori Jun 28 '10 at 20:49
show 3 more comments
feedback

You should be able to use

 Runas /savecred /User:Administrator ...

This should only ask for the password the first time.

However, it is possible that this may fail if there is no password set, which means you may have to set one, or create another admin account with a password.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.