这是一种不使用 cmd、shell 或批处理文件的方法:
首先,您的 Setup-Application 需要被允许写入注册表。您可以通过将“requestedExecutionLevel”设置为“highestAvailable”来实现:
在文件中:“app.manifest”
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
现在您可以使用您的 DotNetFramework 函数来创建您卸载 RegistryKey:
'Setting My Values
Dim ApplicationName As String = "Yourapp"
Dim ApplicationVersion As String = "1.0.0.0"
Dim ApplicationIconPath As String = "%PROGRAMFILES%\Yourapp\yourapp.ico"
Dim ApplicationPublisher As String = "Yourname"
Dim ApplicationUnInstallPath As String = "%PROGRAMFILES%\Yourapp\UNINSTALL.exe"
Dim ApplicationInstallDirectory As String = "%PROGRAMFILES%\Yourapp\"
'Openeing the Uninstall RegistryKey (don't forget to set the writable flag to true)
With My.Computer.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall", True)
'Creating my AppRegistryKey
Dim AppKey As Microsoft.Win32.RegistryKey = .CreateSubKey(ApplicationName)
'Adding my values to my AppRegistryKey
AppKey.SetValue("DisplayName", ApplicationName, Microsoft.Win32.RegistryValueKind.String)
AppKey.SetValue("DisplayVersion", ApplicationVersion, Microsoft.Win32.RegistryValueKind.String)
AppKey.SetValue("DisplayIcon", ApplicationIconPath, Microsoft.Win32.RegistryValueKind.String)
AppKey.SetValue("Publisher", ApplicationPublisher, Microsoft.Win32.RegistryValueKind.String)
AppKey.SetValue("UninstallString", ApplicationUnInstallPath, Microsoft.Win32.RegistryValueKind.String)
AppKey.SetValue("UninstallPath", ApplicationUnInstallPath, Microsoft.Win32.RegistryValueKind.String)
AppKey.SetValue("InstallLocation", ApplicationInstallDirectory, Microsoft.Win32.RegistryValueKind.String)
End With