我正在学习Powershell,我正在在线关注此博客,该博客允许访问远程计算机上已安装的软件。同时跟随代码。我收到此错误,但我在网上找不到任何答案。希望有人可以提供帮助。我真的很感激。
Exception calling "OpenRemoteBaseKey" with "2" argument(s): "Attempted to perform an unauthorized operation."
At line:4 char:1
+ $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $Sr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : UnauthorizedAccessException
You cannot call a method on a null-valued expression.
At line:5 char:1
+ $regKey.OpenSubKey($key)
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
到目前为止,这是我的代码;
$srv = 'testpc01'
$key = "SOFTWARE\Microsoft\Windows\CurrentVersion"
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $Srv)
$regKey.OpenSubKey($key)
谢谢!