如何在 vb.net 中查找特定安装程序的显示版本
How to find a displayversion for a specific installed program in vb.net
我正在尝试获取卸载注册表路径中特定程序的显示版本。我可以从直接路径获取它或列出整个卸载,但我无法根据显示名称和 returns 显示版本找到特定程序。如果您能提供帮助或指导,谢谢。
Public Function GetDisplayLink() As String
On Error Resume Next
Dim strRegPath As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{772811A3-D34B-4594-AF3E-A7C655013E62}\"
Dim regVersion64 As Microsoft.Win32.RegistryKey = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, strWorkstation, Microsoft.Win32.RegistryView.Registry64).OpenSubKey(strRegPath)
Dim strDisplayLink As String = regVersion64.GetValue("DisplayVersion")
GetDisplayLink = "DisplayLink Driver|" & strDisplayLink & "<BR>"
regVersion64 = Nothing
End Function
I cannot get it to find a specific program based on displayname and
returns displayversion.
有几种方法(WMI、Shell、Msi、...)
WMI 是最简单的但是速度慢
使用 Msi 的示例,在 Windows 10 =>
上使用“Microsoft Silverlight”进行测试
Dim sProductName As String = "Microsoft Silverlight"
Dim nResult As UInteger = 0
Dim sProductCode As StringBuilder = New StringBuilder(256)
Dim nIndex As Integer = 0
Do While (True)
nResult = MsiEnumProducts(nIndex, sProductCode)
If (nResult <> 0) Then
Exit Do
End If
Dim nSize As Integer = 256
Dim sbProductName As StringBuilder = New StringBuilder(nSize)
nResult = MsiGetProductInfo(sProductCode.ToString(), "InstalledProductName", sbProductName, nSize)
If (sbProductName.ToString() = sProductName) Then
nSize = 256
Dim sbVersionString As StringBuilder = New StringBuilder(nSize)
nResult = MsiGetProductInfo(sProductCode.ToString(), "VersionString", sbVersionString, nSize)
Console.WriteLine("Product: {0}", sProductName)
Console.WriteLine(vbTab + "Code: {0}", sProductCode.ToString())
Console.WriteLine(vbTab + "Version: {0}", sbVersionString.ToString())
Exit Do
End If
nIndex += 1
Loop
有声明:
<DllImport("Msi.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function MsiEnumProducts(iProductIndex As Integer, lpProductBuf As StringBuilder) As UInteger
End Function
<DllImport("Msi.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function MsiGetProductInfo(szProduct As String, szAttribute As String, lpValueBuf As StringBuilder, ByRef pcchValueBuf As Integer) As UInteger
End Function
我正在尝试获取卸载注册表路径中特定程序的显示版本。我可以从直接路径获取它或列出整个卸载,但我无法根据显示名称和 returns 显示版本找到特定程序。如果您能提供帮助或指导,谢谢。
Public Function GetDisplayLink() As String
On Error Resume Next
Dim strRegPath As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{772811A3-D34B-4594-AF3E-A7C655013E62}\"
Dim regVersion64 As Microsoft.Win32.RegistryKey = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, strWorkstation, Microsoft.Win32.RegistryView.Registry64).OpenSubKey(strRegPath)
Dim strDisplayLink As String = regVersion64.GetValue("DisplayVersion")
GetDisplayLink = "DisplayLink Driver|" & strDisplayLink & "<BR>"
regVersion64 = Nothing
End Function
I cannot get it to find a specific program based on displayname and returns displayversion.
有几种方法(WMI、Shell、Msi、...)
WMI 是最简单的但是速度慢
使用 Msi 的示例,在 Windows 10 =>
上使用“Microsoft Silverlight”进行测试Dim sProductName As String = "Microsoft Silverlight"
Dim nResult As UInteger = 0
Dim sProductCode As StringBuilder = New StringBuilder(256)
Dim nIndex As Integer = 0
Do While (True)
nResult = MsiEnumProducts(nIndex, sProductCode)
If (nResult <> 0) Then
Exit Do
End If
Dim nSize As Integer = 256
Dim sbProductName As StringBuilder = New StringBuilder(nSize)
nResult = MsiGetProductInfo(sProductCode.ToString(), "InstalledProductName", sbProductName, nSize)
If (sbProductName.ToString() = sProductName) Then
nSize = 256
Dim sbVersionString As StringBuilder = New StringBuilder(nSize)
nResult = MsiGetProductInfo(sProductCode.ToString(), "VersionString", sbVersionString, nSize)
Console.WriteLine("Product: {0}", sProductName)
Console.WriteLine(vbTab + "Code: {0}", sProductCode.ToString())
Console.WriteLine(vbTab + "Version: {0}", sbVersionString.ToString())
Exit Do
End If
nIndex += 1
Loop
有声明:
<DllImport("Msi.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function MsiEnumProducts(iProductIndex As Integer, lpProductBuf As StringBuilder) As UInteger
End Function
<DllImport("Msi.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function MsiGetProductInfo(szProduct As String, szAttribute As String, lpValueBuf As StringBuilder, ByRef pcchValueBuf As Integer) As UInteger
End Function