Win10添加右键打开cmd和Powershell窗⼝(管理员⾮管理
员)
1.背景
Win10打开命令⾏窗⼝的⽅法有很多,常见的有
① win+R输⼊cmd;
② win+X选择命令提⽰符;
③ 右键开始菜单选择命令提⽰符。
其中②③均有管理员/⾮管理员,并且可以在 设置 → 个性化 → 任务栏 中改成Powershell。
但有时候需要在指定的⽂件夹打开命令⾏窗⼝或者Powershell,还需要再进⾏cd操作,⽐较⿇烦,所有现在添加右键命令:在此处打开命令⾏(或Powershell)窗⼝,管理员和⾮管理员⽅式。
2.添加⽅法
2.1 ⽅法⼀:直接操作注册表⼿动添加
通过注册表进⾏添加,可以直接win+R,输⼊regedit打开注册表,定位到以下路径(可以直接复制粘贴到注册表编辑器上⾯的地址栏):HKEY_CLASSES_ROOT\Directory\Background\shell\
powershell怎么以管理员身份运行
注意:在进⾏进⼀步操作前请务必备份注册表,以免出现问题,可以进⾏还原。选择 ⽂件-导出 ,全部备份⽂件较⼤,可以选择仅备份上⾯路径的分⽀。
具体可以参考:
2.2⽅法⼆:通过编写.reg⽂件进⾏添加(推荐)
和上⾯其实本质上⼀样,只是通过代码进⾏,更⽅便。
参考:
具体⽅法如下:
2.2.1 实现效果
右键:
在此处打开命令⾏窗⼝
在此处打开命令⾏窗⼝(管理员)
shift + 右键:
在此处打开 Powershell 窗⼝
在此处打开 Powershell 窗⼝(管理员)
其中shift + 右键 实现“在此处打开 Powershell 窗⼝”为系统⾃带,不需要添加
下⾯代码⾥的3和4均是通过隐藏的PowerShell窗⼝来调起powershell(cmd)的,因此会闪过⼀次powershell窗⼝。打开的时候会有⽤户账
户控制弹窗,以确认管理员⾝份,
2.2.2 具体代码
代码如下,Windows直接新建txt,粘贴进去保存,然后选择另存为,保存类型选所有⽂件、编码选ANSI、⽂件名为
<(名字⽆所谓,后缀为.reg就可以)。双击打开,会进⾏两次确认,然后会提⽰“
已成功添加到注册表中”,这
样就成功了!现在可以右键、shift+右键尝试⼀下了!
Windows Registry Editor Version 5.00
; 原⽂链接:
; blog.csdn/cxrsdn/article/details/84538767
; 若原先有,先删除原来的
[-HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHere]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\PowershellAdmin]
; 1.右键:命令⾏
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHere]
@="在此处打开命令⾏窗⼝"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHere\command]
@=" -noexit -command Set-Location -literalPath \"%V\""
; 2.右键:命令⾏(管理员)
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@="在此处打开命令⾏窗⼝(管理员)"
"ShowBasedOnVelocityId"=dword:00639bc8
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@=" /s /k pushd \"%V\""
; 3.shift+右键:Powershell(管理员)
[HKEY_CLASSES_ROOT\Directory\Background\shell\PowershellAdmin]
@="在此处打开 Powershell 窗⼝(管理员)"
"Extended"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\PowershellAdmin\command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\\" -windowstyle hidden -Command $stpath = pwd; Start-Process PowerShell -ArgumentL
; 4.设置右键管理员打开cmd的另⼀种⽅法(可⽤来替换上⾯的2)
; 通过Powershell调起,会闪过⼀次Powershell的窗⼝,去掉下⾯⼏⾏的[; ]可以取消注释
; [-HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHereAdmin]
;
; [HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHereAdmin]
; @="在此处打开命令⾏窗⼝(管理员)"
;
; [HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHereAdmin\command]
; @="PowerShell -windowstyle hidden -Command \" -ArgumentList '/s,/k, pushd,%V' -Verb RunAs\""
说明:
1.前⾯有分号;的是注释;
2.带有"Extended"=""的是shift+右键的,可以⾃⾏调整四个命令是否加这个;
3.可以参考这个链接:进⾏理解