IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

desinstaller un programme avant execution du setup wizard [Débutant]


Sujet :

C#

  1. #1
    Membre actif
    Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    336
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 336
    Points : 227
    Points
    227
    Par défaut desinstaller un programme avant execution du setup wizard
    Bonjour,

    je créé un setup pour installer mon application.
    le problème c'est que je ne peux pas lancer mon setup
    si une autre version est déjà installé.
    Je voudrai pouvoir desinstaller mon programme avant l'installation mais cela ne fonctionne que avec le meme setup.

    voici ce que j'ai:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    [RunInstaller(true)]
        public partial class InstallerTest : System.Configuration.Install.Installer
        {
            public string AppName
            {
                get
                {
                    return "donjons";
                }
            }
     
            public string UninstallString
            {
                get
                {
                    if (Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") != null)
                    {
                        string[] subKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall").GetSubKeyNames();
     
                        string path = string.Empty;
     
                        foreach (string key in subKey)
                        {
                            path = string.Format(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{0}", key);
                            if (Microsoft.Win32.Registry.LocalMachine.OpenSubKey(path).GetValue("DisplayName") != null
                                && Microsoft.Win32.Registry.LocalMachine.OpenSubKey(path).GetValue("DisplayName").ToString().ToLower() == AppName.ToLower())
                            {
                                return Microsoft.Win32.Registry.LocalMachine.OpenSubKey(path).GetValue("UninstallString").ToString().Replace("/I", "/X");
                            }
                        }
                    }
                    return null;
                }
            }
     
            public InstallerTest()
            {
                InitializeComponent();
     
                WriteToEventLog();
     
                this.
                this.BeforeInstall += new InstallEventHandler(InstallerTest_BeforeInstall);
                //this.AfterInstall += new InstallEventHandler(InstallerTest_AfterInstall);
                //this.Committing += new InstallEventHandler(InstallerTest_Committing);
                //this.Committed += new InstallEventHandler(InstallerTest_Committed);
            }
     
            private void InstallerTest_BeforeInstall(object sender, InstallEventArgs e)
            {
                new MsgBox("Before installation \n" + UninstallString, "Before install").ShowDialog();
     
                if (!string.IsNullOrWhiteSpace(UninstallString))
                {
                    new MsgBox("début désinstallation", "uninstall").ShowDialog();
     
                    string batchCode = string.Format("{0} /passive", UninstallString);
     
                    ProcessStartInfo processInfo = new ProcessStartInfo("cmd.exe", "/c " + batchCode);
     
                    processInfo.CreateNoWindow = true;
                    processInfo.UseShellExecute = false;
     
                    Process process = Process.Start(processInfo);
                    process.WaitForExit();
     
                    new MsgBox("Fin désinstallation", "uninstall").ShowDialog();
                }
            }
     
     
     
     
            private void WriteToEventLog()
            {
                System.Diagnostics.EventLog.WriteEntry("InstallerTest", "Installer class has been invoked");
            }
     
            void InstallerTest_Committed(object sender, InstallEventArgs e)
            {
                new MsgBox("Committed", "Committed").ShowDialog();
            }
     
            void InstallerTest_Committing(object sender, InstallEventArgs e)
            {
                new MsgBox("Committing", "Committing").ShowDialog();
            }
     
            void InstallerTest_AfterInstall(object sender, InstallEventArgs e)
            {
                new MsgBox("After installation", "After install").ShowDialog();
            }
        }
    ce que je voudrai ce serai que la desinstallation se passe avant l'execution du setup mais je ne voit pas comment m'y prendre. Auriez-vous une solution ?
    d'avance merci

  2. #2
    Membre expérimenté
    Avatar de charouel
    Homme Profil pro
    Freelance
    Inscrit en
    Mars 2009
    Messages
    618
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2009
    Messages : 618
    Points : 1 454
    Points
    1 454
    Billets dans le blog
    9
    Par défaut
    Tu doit incrémenté la version de setup pour qu'il désinstalle automatiquement l'ancienne version

  3. #3
    Membre actif
    Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    336
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 336
    Points : 227
    Points
    227
    Par défaut
    Justement je ne désire pas faire cela.

    je veux executer ceci:
    que je vais recupérer dans le registre ensuite je remplace /i par /x
    je souhaite executer la commande ENSUITE le setup wizard.

    Je n'ai pas le choix je doit procéder de cette façon

    j'aimerai executer ma commande si elle existe pour ensuite afficher le wizard et faire l'installation.

    Merci pour vos réponses

    EDIT : l'idée c'est d'executer du code avant le setup wizard.
    J'ai ajouter l'appel du primary output de mon exe qui fait l'uninstall avant le primary output de l'installation mais ce ne fonctionne pas non plus.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Inno Setup] Installation programme avant installation
    Par the java lover dans le forum Outils
    Réponses: 17
    Dernier message: 25/09/2008, 21h00
  2. Offusquer un programme avant creation du setup
    Par Aspic dans le forum Général Dotnet
    Réponses: 27
    Dernier message: 22/12/2007, 08h51
  3. executer un programme avant ouverture session
    Par pitikak dans le forum Windows XP
    Réponses: 14
    Dernier message: 21/07/2007, 15h15
  4. Valider avant execution fonction
    Par jeff37 dans le forum ASP
    Réponses: 3
    Dernier message: 08/09/2004, 12h39
  5. Désinstallation de programme...
    Par sekiryou dans le forum Linux
    Réponses: 3
    Dernier message: 18/02/2004, 00h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo