Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
vb
Imports
Imports
Imports
Imports
Imports
Pgina 1
System.Deployment.Application
System.Reflection
System.IO
Microsoft.Win32
System.Security.Policy
Instalador.vb
Pgina 2
Instalador.vb
Pgina 3
''' </summary>
''' <param name="DisplayName">Display Name value from the registry</param>
Private Shared Sub PushUninstallOKButton(ByVal DisplayName As String)
Dim success As Boolean = False
''Find the uninstall dialog.
Dim uninstallerWin As IntPtr = _
FindUninstallerWindow(DisplayName, success)
Dim OKButton As IntPtr = IntPtr.Zero
''If it found the window, look for the button.
If (success) Then
OKButton = FindUninstallerOKButton(uninstallerWin, success)
End If
''If it found the button, press it.
If (success) Then
DeploymentUtilsWin32.DoButtonClick(OKButton)
End If
End Sub
'VB
''' <summary>
''' Find the uninstall dialog.
''' </summary>
''' <param name="DisplayName">Display Name retrieved
''' from the registry.</param>
''' <param name="success">Whether the window was found or not.</param>
''' <returns>Pointer to the uninstall dialog.</returns>
Private Shared Function FindUninstallerWindow(ByVal DisplayName As String, _
ByRef success As Boolean) As IntPtr
''Max number of times to look for the window,
''used to let you out if there's a problem.
Dim i As Integer = 25
Dim w32 As New DeploymentUtilsWin32()
Dim uninstallerWindow As IntPtr = IntPtr.Zero
Do While (uninstallerWindow = IntPtr.Zero AndAlso i > 0)
uninstallerWindow = _
w32.SearchForTopLevelWindow(DisplayName + " Maintenance")
System.Threading.Thread.Sleep(500)
i -= 1
Loop
If (uninstallerWindow = IntPtr.Zero) Then
success = False
Else
success = True
End If
Return uninstallerWindow
End Function
'VB
''' <summary>
''' Find the OK button on the uninstall dialog.
''' </summary>
''' <param name="UninstallerWindow">The pointer to
''' the Uninstall Dialog</param>
''' <param name="success">Whether it succeeded or not.</param>
''' <returns>A pointer to the OK button</returns>
Private Shared Function FindUninstallerOKButton(ByVal UninstallerWindow _
As IntPtr, ByRef success As Boolean) As IntPtr
''max number of times to look for the button,
''lets you out if there's a problem
Dim i As Integer = 25
Dim w32 As New DeploymentUtilsWin32()
Dim OKButton As IntPtr = IntPtr.Zero
Do While (OKButton = IntPtr.Zero AndAlso i > 0)
OKButton = w32.SearchForChildWindow(UninstallerWindow, "&OK")
Instalador.vb
System.Threading.Thread.Sleep(500)
i -= 1
Loop
If (OKButton = IntPtr.Zero) Then
success = False
Else
success = True
End If
Return OKButton
End Function
'VB
''' <summary>
''' Install the new version of the application from a different URL.
''' Then exit this version of the application.
''' Trigger this specifically with Internet Explorer
'''
in case the user has their default browser set to something else.
''' This eliminates any problems running it with Firefox.
''' If you are changing something like the target CPU, or installing
'''
a new prerequisite, run setup.exe.
''' Otherwise, you can just call the application fle directly,
'''
because the user won't have the application installed w/o the
'''
current prerequisites.
''' </summary>
Public Shared Sub InstallNewVersion()
Dim url As String = _
"http://localhost/NewVersion/TestCertExp_VB.application"
System.Diagnostics.Process.Start("iexplore.exe", url)
System.Windows.Forms.Application.Exit()
Return
End Sub
End Class
Pgina 4