这个堆栈帖子和这个看起来都很相似,但我在那里找不到我的解决方案。我在理解 reg 导出与 reg 导入中的行为之间的区别时遇到问题。
在 powershell 中运行 reg export 时,它返回“操作已成功完成”,但 reg import 会抛出一个终止错误,提示“操作已成功完成”。注册表文件被正确导入,即使它被抛出为错误。一个例子:
PS C:\Windows\System32> reg export HKLM\Software\MySoftware C:\Scripts\MyFile.reg
The operation completed successfully.
PS C:\Windows\System32> reg import C:\Scripts\MyFile.reg
reg : The operation completed successfully.
At line:1 char:1
+ reg import C:\Scripts\MyFile.reg
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (The operation completed successfully.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Microsoft 的 reg import 命令文档说返回码是 0 表示成功,1 表示失败。为什么 Powershell 会将成功作为 reg 导出的常规成功消息返回,但将其作为 reg 导入的终止错误抛出?
我以管理员身份运行 Powershell,登录用户是服务器上的本地管理员。任何帮助表示赞赏。