gpt4 book ai didi

windows - Powershell:变量赋值触发模块导入

转载 作者:可可西里 更新时间:2023-11-01 09:52:49 28 4
gpt4 key购买 nike

此代码可在 Powershell 命令行运行,但在从脚本运行时会生成错误:

$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key Hidden 1

当我从我的脚本运行它时,出现以下错误:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer : The module 'HKEY_CURRENT_USER' could not be
loaded. For more information, run 'Import-Module HKEY_CURRENT_USER'.
At C:\Users\mybitch\Desktop\VSS-Customize-Desktop.ps1:19 char:6
+ $key=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (HKEY_CURRENT_US...ersion\Explorer:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule

这是一个简单的任务...为什么 Powershell 会尝试将 HKEY_CURRENT_USER 作为模块导入?为什么行为与 Powershell 命令行如此不同?

最佳答案

错误消息暴露了问题所在。在您的脚本中,显然您正在这样做:

$key = HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer

这是一个无效的分配。你应该按照你描述的去做:

$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'

关于windows - Powershell:变量赋值触发模块导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30536170/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com