此代碼從PowerShell命令行工作,但在腳本運行時產生一個錯誤: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命令行有所不同?
'HKCU:'是一個提供者。你可以檢查'Get-PSDrive',你會看到它。如果它不存在,PowerShell會嘗試從理論上加載它。你從哪裏運行這個腳本?不是任務調度程序是嗎? – Matt
我只是從提升的Powershell命令行調用腳本。 –
Get-PSDrive顯示HKCU已加載。爲什麼它會嘗試重新加載然後失敗? –