使用以下方法获取REG_SZ
值时遇到一些奇怪的问题:
(get-itemproperty -Path "Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\VLC media player" -Name UninstallString).UninstallString
(get-itemproperty -Path "Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\VLC media player" -Name UninstallString).UninstallString
get-itemproperty : Cannot find path 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\VLC media player' because it
does not exist.
At line:1 char:2
+ (get-itemproperty -Path "Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (HKEY_LOCAL_MACH...LC media player:String) [Get-ItemProperty], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand
这种方法适用于另一个REG_SZ
而没有问题,但当我呼叫Uninstall
以下的许多密钥时,它会失败。
具体来说,它适用于:
(get-itemproperty -Path "Registry::HKEY_CURRENT_USER\Software\Microsoft\Command Processor" -Name autorun).AutoRun
我的系统上存在两个数据条目,在regedit中可见....
然而,非常有趣的是,它们不存在于:
中Get-ChildItem "Registry::HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\uninstall\"
还有几个“缺失”键。这看起来像我不熟悉的一些奇怪的注册表命名空间虚拟化(类似于HKEY_CLASSES_ROOT)?
答案 0 :(得分:4)
A forum thread lead me to the answer.
讨论the virtualization of the registry for 32-bit and 64-bit programs。
在这种情况下,由于密钥“缺失”,必须检查其他路径(请注意,我应该在尝试任何“错误”操作之前检查条件中test-path
的路径)。
PS > (dir HKLM:\SOFTWARE\wow6432node\Microsoft\Windows\CurrentVersion\Uninstall | measure).count
134
PS > (dir hklm:\software\microsoft\windows\currentversion\uninstall | measure).count
134
所以,我必须运行32位的powershell.exe。
PS > [Environment]::Is64BitProcess
False
此外,HKEY_CLASSES_ROOT\Installer\Products
是列出随Windows Installer一起安装的程序的另一个位置。
This answer is helpful in regards to 32-bit vs. 64-bit powershell.exe
The solution to this problem is robust。我modified the previously linked function a bit使其更易于访问。
P.S。我在macbook pro上运行Windows 7 on bootcamp。奇怪的是,无论我执行的powershell.exe是什么,它都是32位。我无法看到注册表项,无论该位置是否位于wow6432node
。