1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
'Ajouter une Ref à :
'-System.Configuration.Install
'-System.Runtime.InteropServices
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.Linq
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Diagnostics
Imports System.IO
<RunInstaller(True)> _
Public Class MonInstallerHelper
Inherits Installer
Public Sub New()
End Sub
Public Overrides Sub Rollback(ByVal savedState As System.Collections.IDictionary)
MyBase.Rollback(savedState)
End Sub
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
End Sub
Protected Overrides Sub OnAfterInstall(ByVal savedState As System.Collections.IDictionary)
MyBase.OnAfterInstall(savedState)
End Sub
Public Overrides Sub Commit(ByVal savedState As System.Collections.IDictionary)
MyBase.Commit(savedState)
End Sub
Protected Overrides Sub OnAfterRollback(ByVal savedState As System.Collections.IDictionary)
MyBase.OnAfterRollback(savedState)
End Sub
Protected Overrides Sub OnAfterUninstall(ByVal savedState As System.Collections.IDictionary)
MyBase.OnAfterUninstall(savedState)
End Sub
Protected Overrides Sub OnBeforeRollback(ByVal savedState As System.Collections.IDictionary)
MyBase.OnBeforeRollback(savedState)
End Sub
Protected Overrides Sub OnBeforeUninstall(ByVal savedState As System.Collections.IDictionary)
MyBase.OnBeforeUninstall(savedState)
End Sub
Protected Overrides Sub OnCommitted(ByVal savedState As System.Collections.IDictionary)
MyBase.OnCommitted(savedState)
End Sub
Protected Overrides Sub OnCommitting(ByVal savedState As System.Collections.IDictionary)
MyBase.OnCommitting(savedState)
End Sub
Public Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary)
MyBase.Uninstall(savedState)
End Sub
'Overriddes le plus important
'Permet de lire valeurs Custom Action Data
Protected Overrides Sub OnBeforeInstall(ByVal savedState As System.Collections.IDictionary)
'MyBase.OnBeforeInstall(savedState)
Try
'Sauvegarde l'etat actuel d'installation pou y revenir eventuellement
MyBase.OnBeforeInstall(savedState)
Dim fileInfo As FileInfo = New FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location)
'Lit les valeurs Custom Action Data
Dim sProgram As String = Context.Parameters("Run")
sProgram = Path.Combine(fileInfo.DirectoryName, sProgram)
Trace.WriteLine("Install sProgram= " + sProgram)
OpenWithStartInfo(sProgram)
Catch exc As Exception
Context.LogMessage(exc.ToString())
Throw
End Try
End Sub
'OpenWithStartInfo lancera le processus KB.EXE avec Processus.Start
'et Context de Processus ("run", "WaitForExit")
'Fera une pause du processus Setup General tant que
'execution de KB.EXE n'est pas terminee.
Private Sub OpenWithStartInfo(ByVal sProgram As String)
Dim startInfo As ProcessStartInfo = New ProcessStartInfo(sProgram)
startInfo.WindowStyle = ProcessWindowStyle.Normal
Dim ExcludeKeys() As String = New String() {"run", "WaitForExit"}
startInfo.Arguments = ContextParametersToCommandArguments(Context, ExcludeKeys)
Trace.WriteLine("run the program " & sProgram & startInfo.Arguments)
Dim p As Process = Process.Start(startInfo)
'Utilise API window pour Style Fenetre
'autrement le Fenetre n'est poas active
ShowWindow(p.MainWindowHandle, WindowShowStyle.Show) '
SetForegroundWindow(p.MainWindowHandle)
'Mettre au dessus de la fenetre Setup General
BringWindowToTop(p.MainWindowHandle)
Trace.WriteLine("the program Responding= " + p.Responding)
'Demander à Setup General d'attendre fin du processus KB.EXE.
If ((Context.IsParameterTrue("WaitForExit"))) Then
p.WaitForExit()
End If
End Sub
'Fonction Utilitaire StringBuilder
'rajoute arguments("run") & ("WaitForExit") à la collection
'Context.Parametres (prop Context de la classe MonInstallerHelper)
Private Shared Function ContextParametersToCommandArguments(ByVal context As InstallContext, ByVal ExcludeKeys() As String) As String
ExcludeKeys = ToLower(ExcludeKeys)
Dim sb As StringBuilder = New StringBuilder()
For Each de As DictionaryEntry In context.Parameters
Dim sKey As String = CType(de.Key, String)
Dim bAdd As Boolean = True
If (ExcludeKeys IsNot Nothing) Then
bAdd = (Array.IndexOf(ExcludeKeys, sKey.ToLower()) < 0)
End If
If (bAdd) Then
AppendArgument(sb, sKey, CType(de.Value, String))
End If
Next
Return sb.ToString()
End Function
Public Shared Function AppendArgument(ByVal sb As StringBuilder, ByVal Key As String, ByVal value As String) As StringBuilder
sb.Append(" /")
sb.Append(Key)
'Si value est une chaine vide signe = est attendu
If (value IsNot Nothing) Then
sb.Append("=")
sb.Append(value)
End If
Return sb
End Function
#Region "FS library methods"
Public Shared Function ToLower(ByVal Strings() As String) As String()
If (Strings IsNot Nothing) Then
For i As Integer = 0 To Strings.Length
Strings(i) = Strings(i).ToLower()
Next
End If
Return Strings
End Function
#End Region '//"FS library methods"
'Partie API Win "P/INVOKE"
<DllImport("user32.dll")> _
Private Shared Function BringWindowToTop(ByVal hWnd As IntPtr) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As WindowShowStyle) As Boolean
End Function
'Enumeration des differentes facons d'afficher une fenetre Window
'lors de l'appel API ShowWindow
Private Enum WindowShowStyle
Hide = 0
ShowNormal = 1
ShowMinimized = 2
ShowMaximized = 3
Maximize = 3
ShowNormalNoActivate = 4
Show = 5
Minimize = 6
ShowMinNoActivate = 7
ShowNoActivate = 8
Restore = 9
ShowDefault = 10
ForceMinimized = 11
End Enum
End Class |
Partager