runas 的别名 DOS 命令
我希望能够为 dos 命令指定别名以与 runas 命令结合使用,
特别是我厌倦了获取 BIDS 的完整路径("C:\Program Files\Microsoft Visual Studio 9.0\Common7\ IDE\devenv.exe"
),我想像 MS 为 ssms
所做的那样使用别名。
有人知道该怎么做吗?我知道我可以使用批处理文件来完成此任务,但我真的不想这样做。
runas /user:user /netonly bids
与
runas /user:user /netonly "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这种
doskey
技术是 SuperUser 的特色,请参阅 https://superuser.com/questions/49170/create-an-alias-in-windows-xp">https:// /superuser.com/questions/49170/create-an-alias-in-windows-xp。它的问题是您无法定义 runas 使用的别名。您可以定义一个别名,其中包含
runas
和您要运行的命令,但这将无法重用。但是这样做怎么样:然后您可以像这样使用
当然,这需要您为您想要的每个快捷方式设置一个环境变量,但我认为这并不比设置 doskey 更大的要求> 别名本身。无论如何,它不会创建文件,也不需要在
path
中放置任何内容。更新:
我自己没有尝试过,但看起来您确实可以设置它并忘记它。
cmd.exe
启动时都可以设置DOSKEY
别名 使用注册表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 bothrunas
and the command you want to run, but this would not then be reusable. But what about doing this:Which you can then use like
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 thepath
.Update:
I didn't try it myself, but it certainly looks like you can set it and forget it.
DOSKEY
alias can be set each timecmd.exe
starts using the registry我认为您遇到的问题是命令行被评估为新用户 - 因此除非新用户也可以访问您的别名,否则它将无法工作。
编辑:您可以通过创建一个方便放置的批处理文件(或快捷方式?)来解决这个问题,该文件启动 BIDS 并运行它?
编辑:
请参阅此处和此处 有关选择命令的信息
示例用法:
I think the problem you're hitting is that the command line is evaluated as the new user - so unless the new user also has access to your alias, it won't work.
Edit: It's possible you could work around this by creating a conveniently placed batch file (or shortcut?) which launches BIDS and RunAs'ing that?
Edit:
See here and here for info on the choice command
Sample usage:
这是一个将在命令 shell 上设置别名的脚本。该脚本为您提供了难以捉摸的“WHERE”命令:
Here is a script that will setup alias's on your command shells. This script gives you the elusive "WHERE" command :