2

On my laptop running Windows 8.1, I want to invoke a mklink command as admin, How could I run runas in an ordinary command line session? I tried Runas /user:administrator "mklink /d c:\doc c:\users\•••"

It can not execute with neither my password or an empty password. Just as most home user, I haven't explicitly set up the password of the built in administrator.

I can open up a runas admin command prompt box, but it's very inconvenient. I wish I can do it as sudo. Thanks.


A solution I found through Powershell:

c:\> @powershell saps cmd -verb runas

start-process in its short form. However, another command prompt with separate environment variables must be forced and I can't directly embed my command "mklink ..." into this statement. It's still more convenient than finding out an icon with silly mouse clicks.

chingNotCHing
  • 1,196
  • 8
  • 13
  • Did you try - set a password for admin or add a new user and give it the roll of administrator? – tgkprog Jan 23 '14 at 09:16
  • I guess an explicit setup of an administrator will do. But I m puzzled what the exact command can do the same as the runas click does? It needs no enabling of the default admin. – chingNotCHing Jan 23 '14 at 11:56
  • You *can* embed mklink. Just shift params around: `saps -verb runas mklink /d somepath somepath2`. It should inherit environment variables, unlike `runas /user`. – Bob Jan 24 '14 at 13:44
  • Thanks. I've tried but it doesn't work. It seems that an individual .exe or .cmd is a must for start-process runas. – chingNotCHing Jan 24 '14 at 15:01
  • @chingNotCHing Yea, looks like it doesn't like `/d`, and `mklink` is not actually a command, but a cmd built-in - try explicit args and quoting, and run `mklink` as an argument of `cmd`: `powershell -c "start -verb runas cmd -argumentlist '/c mklink /d C:\full\path D:\full\path'" - keep in mind that neither `Start-Process` or `runas` from cmd will preserve the working directory, so always specify the full path. – Bob Jan 25 '14 at 13:44

0 Answers0