Powershell 创建新的注册表值

xew*_*cox 3 powershell

我想在此路径“Computer\\HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\16.0\\Excel\\Security”中创建一个新的注册表值\n它应该是安全密钥内的一个新的“DWORD” “VBAWarnings”和值应该是一。

\n

我尝试过以下方法:

\n
New-ItemProperty \xe2\x80\x93Path "HKCU:\\Software\\Microsoft\\Office\\16.0\\Outlook\\Security" -Value "VBAWarnings"  -PropertyType "DWORD"\n
Run Code Online (Sandbox Code Playgroud)\n

但是它没有创建任何内容,并且不确定我收到的每个错误消息是什么“

\n
((Get-Process MicrosoftEdgeCP -ErrorA.ps1:1 char:124\n+ ... ce\\16.0\\Outlook\\Security" -Value "VBAWarnings"  -PropertyType "DWORD"\n+                                                                         ~\nThe string is missing the terminator: ".\n    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException\n    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString"\n
Run Code Online (Sandbox Code Playgroud)\n

小智 5

@AdminOfThings 和 @Neko Musume 已正确回答了这个问题。我想添加显示完成的代码的步骤,以及将来如何解决这个问题。首先,代码:

New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\16.0\Outlook\Security" -Name "VBAWarnings" -PropertyType "DWORD" -Value "1"
Run Code Online (Sandbox Code Playgroud)

每当您创建新的 powershell 代码时,请使用 Powershell ISE(集成脚本引擎)。这个界面的好处是它具有智能感知功能,在您编写代码时会弹出有用的信息。

为了复制这一点,在 ISE 窗口的脚本部分(白色部分)中,我输入:

New-Itemproperty -
Run Code Online (Sandbox Code Playgroud)

当我添加破折号时,它给了我一个可供选择的项目列表。我选择了最上面的一个,那就是路径。然后我继续代码:

New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\16.0\Outlook\Security" -
Run Code Online (Sandbox Code Playgroud)

它再次向我显示了一个选项列表,我选择了首选选项“名称”。继续,直到我看到默认选择(例如 -force 之类的东西)。当您在 powershell 中使用命令时,这是一个很好的经验法则。