我试图通过右键单击上下文菜单控制 Windows 更新。我有注册表项,可以在注册表中添加和/或删除值来完成此操作。我可以成功执行单个命令。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\Windows Update]
"SubCommands"="Pause updates;Resume updates;Show or hide updates;Open Windows update"
"icon"="wuapi.dll,-0"
"Position"="Bottom"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Pause updates]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Pause updates\command]
@="reg import pausewu.reg"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Resume updates]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Resume updates\command]
@="reg import resumewu.reg"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Show or hide updates]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Show or hide updates\command]
@="cmd /c wushowhide.diagcab"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Open Windows update]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Open Windows update\command]
@="cmd /c start ms-settings:windowsupdate"
我需要同时执行两个命令,但是当我添加第二个命令时,两个命令都不会运行。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\Windows Update]
"SubCommands"="Pause updates;Resume updates;Show or hide updates;Open Windows update"
"icon"="wuapi.dll,-0"
"Position"="Bottom"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Pause updates]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Pause updates\command]
@="reg import pausewu.reg" && echo "cmd /c start ms-settings:windowsupdate"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Resume updates]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Resume updates\command]
@="reg import resumewu.reg" && echo "cmd /c start ms-settings:windowsupdate"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Show or hide updates]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Show or hide updates\command]
@="reg import resumewu.reg" && echo "cmd /c wushowhide.diagcab"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Open Windows update]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Open Windows update\command]
@="cmd /c start ms-settings:windowsupdate"
这在技术上是可行的,但可能不是执行此操作的最佳方法。
如何
为了运行多个命令,它们需要是“单行”命令。命令序列必须能够在命令提示符中的一行中运行。这意味着它们需要包含在 之后的引号 (
"
) 中@=
。测试它的一个好方法是复制 和 之间的所有内容
"
并将其粘贴到“运行”对话框中。这将起作用:
注意:命令中使用的任何引号或反斜杠都需要转义 (
\"
,\\
)。更好的方法
更好的替代方法是创建批处理文件并运行它们。创建一个
pause.bat
包含您的命令的文件(例如:):然后在您的文件中使用以下内容
.reg
:注意:同样,命令中使用的任何引号或反斜杠都需要转义 (
\"
,\\
)。为什么这样更好
由于多种原因,这种方法更好:
.reg
一次文件,就可以根据需要对批处理文件进行修改。手动编辑注册表越少越好。我要从注册表中执行 2 个命令。它要简单得多,而且应该足够安全,不会破坏注册表。我还将NSudo.exe添加到等式中以隐藏命令窗口。