[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[注册表类] [求助]reg add 命令字数太长如何解决?

reg query "HKCR\Microsoft.PowerShellScript.1\shell"
reg add "HKCR\Microsoft.PowerShellScript.1\shell\runas" /f
reg add "HKCR\Microsoft.PowerShellScript.1\shell\runas" /v "HasLUAShield" /f
reg add "HKCR\Microsoft.PowerShellScript.1\shell\runas\Command" /f

:: PowerShell.exe "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"

reg add "HKCR\Microsoft.PowerShellScript.1\shell\runas\Command" /ve /d "PowerShell.exe \"-Command\" \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\""

最后一句应该是字符太长无法执行?

绝对不是太长,才多少个字节。试试这个:功能未测试,只是验证加入注册表而已。
  1. reg add "HKCR\Microsoft.PowerShellScript.1\shell\runas\Command" /ve /d "cmd.exe /c & call powershell.exe -command \"if((Get-ExecutionPolicy).toString() -ne 'AllSigned'){Set-ExecutionPolicy -Scope Bypass}\""
复制代码
QQ: 己阵亡
脚本优先 [PowerShell win10]

TOP

回复 2# xczxczxcz


    本意实现右键管理员运行ps1文件;上述reg add执行成功,功能暂时还不满足。

TOP

本帖最后由 WHY 于 2019-10-27 15:48 编辑

数数看,双引号有几个,双引号对(相邻的两个双引号为一对)有几对,&字符在引号对外面还是里面?
如果位于双引号对之外就要转义。
在批处理中%也要转义。

TOP

我都是直接导入或用powerun运行.reg文件,执行速度快很多,还不会出错

TOP

本帖最后由 WHY 于 2019-10-28 09:05 编辑

好吧,贴个现成的
  1. reg add "HKCR\Microsoft.PowerShellScript.1\shell\runas\Command" /ve /d "%winDir%\System32\WindowsPowerShell\v1.0\PowerShell.exe -C \"Set-ExecutionPolicy -Scope Process Bypass; ^& '%%1'\"" /f
复制代码

TOP

返回列表