找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 27555|回复: 5

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

[复制链接]
发表于 2019-10-25 21:35:43 | 显示全部楼层 |阅读模式
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'\""

最后一句应该是字符太长无法执行?
发表于 2019-10-26 16:14:11 | 显示全部楼层
绝对不是太长,才多少个字节。试试这个:功能未测试,只是验证加入注册表而已。

  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}""
复制代码
 楼主| 发表于 2019-10-26 21:58:13 | 显示全部楼层
回复 2# xczxczxcz


    本意实现右键管理员运行ps1文件;上述reg add执行成功,功能暂时还不满足。
发表于 2019-10-26 22:54:43 | 显示全部楼层
本帖最后由 WHY 于 2019-10-27 15:48 编辑

数数看,双引号有几个,双引号对(相邻的两个双引号为一对)有几对,&字符在引号对外面还是里面?
如果位于双引号对之外就要转义。
在批处理中%也要转义。
发表于 2019-10-27 08:51:12 | 显示全部楼层
我都是直接导入或用powerun运行.reg文件,执行速度快很多,还不会出错
发表于 2019-10-27 15:55:14 | 显示全部楼层
本帖最后由 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
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 11:26 , Processed in 0.018071 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表