Windows7: Gaining administrator rights in CLI without being prompted for password

0

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,

liori

Posted 2010-06-28T20:30:32.437

Reputation: 3 044

Answers

1

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

BloodPhilia

Posted 2010-06-28T20:30:32.437

Reputation: 27 374

Most of that script don't need admin rights, so I'd like to avoid running full script with full privileges. – liori – 2010-06-28T20:33:56.393

@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 – 2010-06-28T20:35:21.477

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 – 2010-06-28T20:41:54.163

Perhaps this is something for you: http://sourceforge.net/projects/sudowin/ OR http://www.howtogeek.com/howto/windows-vista/sudo-for-windows-vista/

– BloodPhilia – 2010-06-28T20:43:15.097

I assumed there is something that doesn't require installing 3rd party software, like in a typical Linux installation... – liori – 2010-06-28T20:49:17.877

Not really, it's a much annoyed about subject really... that's why these 3rd party programs were created. The latter, http://www.howtogeek.com/howto/windows-vista/sudo-for-windows-vista/, should work pretty good.

– BloodPhilia – 2010-06-28T20:53:49.507

@liori - on second thoughts, check this out: http://technet.microsoft.com/en-us/magazine/2007.06.utilityspotlight.aspx

– BloodPhilia – 2010-06-28T20:56:36.473

I couldn't get sudowin to work in Win7. Both Start++ and the elevate script interactively show confirmation dialog, which I want to avoid. – liori – 2010-07-01T16:16:16.083

0

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.

sgmoore

Posted 2010-06-28T20:30:32.437

Reputation: 5 961