Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alias DOS command for runas

Tags:

alias

dos

I'd like to be able to alias a dos command to use in conjunction with the runas command

specifically I'm tired of getting the full path to BIDS ("C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"), and I'd like to alias like MS has done for ssms.

Anyone know how to do this? I know I can accomplish this with a batch file, but I'd really rather not.

runas /user:user /netonly bids

vs.

runas /user:user /netonly "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
like image 968
Bobby B Avatar asked Oct 15 '22 01:10

Bobby B


1 Answers

This doskey technique is featured over at SuperUser, see https://superuser.com/questions/49170/create-an-alias-in-windows-xp.

The problem with it is that you can't define an alias to be used by runas. You could define an alias that included both runas and the command you want to run, but this would not then be reusable. But what about doing this:

SET BIDS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe
DOSKEY r=runas /user:user /netonly "%$1%"

Which you can then use like

r bids

Of course this requires you to set an environment var for each shortcut you 'd like to have, but I think this is no greater requirement than setting the doskey alias itself. In any case, it doesn't create a file and it doesn't require that anything be placed in the path.

Update:

I didn't try it myself, but it certainly looks like you can set it and forget it.

  • The environment variables can be set through Windows' system settings (see image)
  • The DOSKEY alias can be set each time cmd.exe starts using the registry

enter image description here

like image 155
Jon Avatar answered Oct 19 '22 09:10

Jon