示例#1
0
 static public void Uninstall(int version)
 {
     try
     {
         if (InstalledSoftware.NameContain("teamviewer", "msi"))
         {
             Process process = new Process();
             if (version == 9)
             {
                 try
                 {
                     Microsoft.Win32.RegistryKey registryKey64 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\TeamViewer\Version9");
                     RegistryKey registryKey32 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\TeamViewer\Version9");
                     if (!OS.Is64Bit())
                     {
                         process.StartInfo.WorkingDirectory = Registry.GetValue(registryKey32.Name, "InstallationDirectory", "NOT FOUND").ToString();
                         process.StartInfo.FileName         = string.Format(Registry.GetValue(registryKey32.Name, "InstallationDirectory", "NOT FOUND").ToString() + "\\uninstall.exe");
                     }
                     else
                     {
                         process.StartInfo.WorkingDirectory = Registry.GetValue(registryKey64.Name, "InstallationDirectory", "NOT FOUND").ToString();
                         process.StartInfo.FileName         = string.Format(Registry.GetValue(registryKey32.Name, "InstallationDirectory", "NOT FOUND").ToString() + "\\uninstall.exe");
                     }
                 }
                 catch (System.Exception) { tvistallpath = "notinstalled"; }
             }
             else
             {
                 process.StartInfo.WorkingDirectory = TeamViewer.Path;
                 process.StartInfo.FileName         = string.Format(TeamViewer.Path + "\\uninstall.exe");
             }
             process.StartInfo.Arguments = " /S";
             process.Start();
             bool done = false;
             process.EnableRaisingEvents = true;
             process.Exited += new EventHandler((object sender, EventArgs e) => { done = true; });
             while (done != true)
             {
                 Application.DoEvents(); Thread.Sleep(1);
             }
         }
         if (InstalledSoftware.NameContain2("teamviewer", "msi"))
         {
             Process process = new Process();
             process.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + "\\TeamViewer";
             process.StartInfo.FileName         = "msiexec.exe";
             process.StartInfo.Arguments        = " /x \"" + Directory.GetCurrentDirectory() + "\\TeamViewer\\" + version + "\\TeamViewer_Host.msi\" /norestart /qn";
             process.Start();
             bool done = false;
             process.EnableRaisingEvents = true;
             process.Exited += new EventHandler((object sender, EventArgs e) => { done = true; });
             while (done != true)
             {
                 Application.DoEvents(); Thread.Sleep(1);
             }
         }
     }
     catch (Exception exc)
     {
         MessageBox.Show("Стандартное сообщение таково: ");
         MessageBox.Show(exc.ToString());
         MessageBox.Show("Свойство StackTrace: " + exc.StackTrace);
         MessageBox.Show("Свойство Message: " + exc.Message);
         MessageBox.Show("Свойство TargetSite: " + exc.TargetSite);
     }
 }