如何检查记事本++;是使用Powershell安装的

如何检查记事本++;是使用Powershell安装的,powershell,Powershell,我正在编写一些powershell脚本,以检查笔记本电脑上是否安装了notepad++。虽然我对此有些问题 代码如下: # Variable(s) $regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Notepad++" # # Check if Notepad ++ is already installed. If($regkey) { Write-output "Notepad++ is already installed on

我正在编写一些powershell脚本,以检查笔记本电脑上是否安装了notepad++。虽然我对此有些问题

代码如下:

# Variable(s)

$regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Notepad++"
#
# Check if Notepad ++ is already installed.

If($regkey)
{
    Write-output "Notepad++ is already installed on your machine."
}
Else
{
    Write-Output "Notepad++ is not installed on your machine."
} 
我手动卸载了记事本+。然后我执行了脚本,显示的输出消息是notepad++已安装,而notepad++未安装。为什么会这样


任何帮助都将不胜感激。

您永远不会测试注册表路径是否存在

If($regkey){}
始终返回
True
,因为变量不为null,所以始终安装记事本+

尝试此操作,它会检查注册表路径是否存在:

if(Test-Path "hklm:\SOFTWARE\Wow6432Node\Notepad++"){
    Write-output "Notepad++ is already installed on your machine."
}
Else{
    Write-Output "Notepad++ is not installed on your machine."
} 

您好,我刚刚重新安装了notepad++并执行了您推荐的脚本,它仍然打印出不正确的输出消息,在本例中,它是未安装的,当它安装时。现在,notepad++已安装在我的计算机上,但当我运行脚本时,输出显示为未安装。您确定您的notepad++存储在Wow6432Node中吗?我的存储在里面,没有问题,它说“已安装”是的,我现在正在查看它,它在“HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Notepad++-它可能存储在其他地方吗?只需测试此代码并告诉我错误:
测试路径”hklm:\SOFTWARE\Wow6432Node\Notepad++“
。我的返回
True
Nice script+1,但有一个常见的误解。
$w32.DisplayName
的输出在这里
Notepad++(64位x64)
Wow64表示windows64上的Windows,因此32Node是32位子系统。
$w64=Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | where-Object DisplayName -like 'NotePad++*'
$w32=Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*  | where-Object DisplayName -like 'NotePad++*'
if ($w64 -or $w32)
{
    Write-output "Notepad++ is already installed on your machine."
}
Else{
    Write-Output "Notepad++ is not installed on your machine."
}