Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Downloading & Executing an Installer - User Cancels

Downloading & Executing an Installer - User Cancels

Scheduled Pinned Locked Moved C#
helpquestionannouncement
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I have an update process in my app that downloads an installer and runs it. If the user cancels the installer it throws a Win32Exception. The problem is that in the Catch all I get is the Exception with the message "The operation was cancelled by the user". Other than the text of the message, there's really no way to know for sure what exception occurred. I don't want to rely on the exception message. Any way to trap this specific issue? Here's my code:

    private static void StartInstaller()
    {
    try
    {
    // Start the installler
    _ = Process.Start(_localSetupFile);

        // Wait until it's started
        Process\[\] processes;
    
        do
        {
            processes = Process.GetProcessesByName(\_processName);
            Thread.Sleep(1000);
        }
        while (processes.Length == 0);
    }
    catch (Win32Exception e)
    {
        // Problem here
    }
    catch (Exception e)
    {
        // Handle the error
        throw;
    }
    

    }

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    D Graeme_GrantG A K 4 Replies Last reply
    0
    • K Kevin Marois

      I have an update process in my app that downloads an installer and runs it. If the user cancels the installer it throws a Win32Exception. The problem is that in the Catch all I get is the Exception with the message "The operation was cancelled by the user". Other than the text of the message, there's really no way to know for sure what exception occurred. I don't want to rely on the exception message. Any way to trap this specific issue? Here's my code:

      private static void StartInstaller()
      {
      try
      {
      // Start the installler
      _ = Process.Start(_localSetupFile);

          // Wait until it's started
          Process\[\] processes;
      
          do
          {
              processes = Process.GetProcessesByName(\_processName);
              Thread.Sleep(1000);
          }
          while (processes.Length == 0);
      }
      catch (Win32Exception e)
      {
          // Problem here
      }
      catch (Exception e)
      {
          // Handle the error
          throw;
      }
      

      }

      If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Is the installer an .MSI?

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • K Kevin Marois

        I have an update process in my app that downloads an installer and runs it. If the user cancels the installer it throws a Win32Exception. The problem is that in the Catch all I get is the Exception with the message "The operation was cancelled by the user". Other than the text of the message, there's really no way to know for sure what exception occurred. I don't want to rely on the exception message. Any way to trap this specific issue? Here's my code:

        private static void StartInstaller()
        {
        try
        {
        // Start the installler
        _ = Process.Start(_localSetupFile);

            // Wait until it's started
            Process\[\] processes;
        
            do
            {
                processes = Process.GetProcessesByName(\_processName);
                Thread.Sleep(1000);
            }
            while (processes.Length == 0);
        }
        catch (Win32Exception e)
        {
            // Problem here
        }
        catch (Exception e)
        {
            // Handle the error
            throw;
        }
        

        }

        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

        Graeme_GrantG Offline
        Graeme_GrantG Offline
        Graeme_Grant
        wrote on last edited by
        #3

        Have you looked at ClickOnce? I have a Silent Updater for .Net Framework v3.5+ that takes out all of the hard work: Silent ClickOnce Installer for Winform & WPF in C# & VB[^]. If your app is Dot Net Core Framework, I have a new article that I will release very soon, just need to finish the article writeup.

        Graeme


        "I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee

        1 Reply Last reply
        0
        • K Kevin Marois

          I have an update process in my app that downloads an installer and runs it. If the user cancels the installer it throws a Win32Exception. The problem is that in the Catch all I get is the Exception with the message "The operation was cancelled by the user". Other than the text of the message, there's really no way to know for sure what exception occurred. I don't want to rely on the exception message. Any way to trap this specific issue? Here's my code:

          private static void StartInstaller()
          {
          try
          {
          // Start the installler
          _ = Process.Start(_localSetupFile);

              // Wait until it's started
              Process\[\] processes;
          
              do
              {
                  processes = Process.GetProcessesByName(\_processName);
                  Thread.Sleep(1000);
              }
              while (processes.Length == 0);
          }
          catch (Win32Exception e)
          {
              // Problem here
          }
          catch (Exception e)
          {
              // Handle the error
              throw;
          }
          

          }

          If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #4

          Win32Exception has a NativeErrorCode property which should return 1223 (0x4C7) when the user stops a process starting at a UAC prompt. An example from my own code where I do something similar is probably clearer than more words!

          private static void RestartWithRunAs(ProcessStartInfo psi) {
            psi.UseShellExecute = true;
            psi.ErrorDialog = true;
            psi.Verb = "runas";
            try {
              Process.Start(psi);
            } catch (System.ComponentModel.Win32Exception exc) {
              // Accept cancelled by user as a valid action
              const Int32 CancelledByUser = 1223;
              if (exc.NativeErrorCode != CancelledByUser) {
                // MessageBox.Show(exc.ToString(), "Restart failure");
                throw;
              }
            }
          }
          

          See also System Error Codes (1000-1299) (WinError.h) - Win32 apps | Microsoft Learn[^] Alan.

          K 1 Reply Last reply
          0
          • A Alan N

            Win32Exception has a NativeErrorCode property which should return 1223 (0x4C7) when the user stops a process starting at a UAC prompt. An example from my own code where I do something similar is probably clearer than more words!

            private static void RestartWithRunAs(ProcessStartInfo psi) {
              psi.UseShellExecute = true;
              psi.ErrorDialog = true;
              psi.Verb = "runas";
              try {
                Process.Start(psi);
              } catch (System.ComponentModel.Win32Exception exc) {
                // Accept cancelled by user as a valid action
                const Int32 CancelledByUser = 1223;
                if (exc.NativeErrorCode != CancelledByUser) {
                  // MessageBox.Show(exc.ToString(), "Restart failure");
                  throw;
                }
              }
            }
            

            See also System Error Codes (1000-1299) (WinError.h) - Win32 apps | Microsoft Learn[^] Alan.

            K Offline
            K Offline
            Kevin Marois
            wrote on last edited by
            #5

            Thanks. I'll give it a try

            If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

            1 Reply Last reply
            0
            • K Kevin Marois

              I have an update process in my app that downloads an installer and runs it. If the user cancels the installer it throws a Win32Exception. The problem is that in the Catch all I get is the Exception with the message "The operation was cancelled by the user". Other than the text of the message, there's really no way to know for sure what exception occurred. I don't want to rely on the exception message. Any way to trap this specific issue? Here's my code:

              private static void StartInstaller()
              {
              try
              {
              // Start the installler
              _ = Process.Start(_localSetupFile);

                  // Wait until it's started
                  Process\[\] processes;
              
                  do
                  {
                      processes = Process.GetProcessesByName(\_processName);
                      Thread.Sleep(1000);
                  }
                  while (processes.Length == 0);
              }
              catch (Win32Exception e)
              {
                  // Problem here
              }
              catch (Exception e)
              {
                  // Handle the error
                  throw;
              }
              

              }

              If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

              K Offline
              K Offline
              kdbueno
              wrote on last edited by
              #6

              winx does not appear in win 32, without first algorithmics of yield and or structure.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups