此代码从Powershell命令行运行,但从脚本运行时会生成错误:
$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key Hidden 1
Run Code Online (Sandbox Code Playgroud)
当我从我的脚本运行它时,我收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
这是一个简单的任务......为什么Powershell会尝试导入HKEY_CURRENT_USER模块?为什么行为与Powershell命令行有如此不同?