none
Excel Add-in Uninstalling, check whether Excel is opened or not. RRS feed

  • Question

  • Hi

    I have Implemented an Excel Add-in.

    I have created a setup and installed the same in the User's Machine. It is working properly.

    When the Excel is opened and user, is making some operations.

    In Middle, he comes to Control Panel and uninstall the Installed add-in.

    Even though the Add-in is uninstalled, user is able to perform all the operations in the opened work.

    In order not to happen this, i am planning to follow the below approach.

    At the time of uninstalling the Add-in.

    I have to check, whether there is any opened Excel workbook.

    if opened, i should show a message to user, saying "Please close the Opened Excel Workbooks and complete the process"

    But i don't know, which Event should be used and how that will be associated with the setup.

    As per my research, I was able to figure out the "WorkbookAddinUninstall" Event but not pretty sure, whether this will be useful or not.

    If useful, don't know how to use and check for the Excel Process.

    If any sample code how this event will be working and to check for opened Excel Instance will be of helpful to me.

    Thanks

    Nihar

    Wednesday, July 26, 2017 10:39 AM

All replies

  • Hi,
    This is a sample code that estimates if a process of Excel is running. (VB.NET)
    Dim proc As System.Diagnostics.Process
    For Each proc In System.Diagnostics.Process.GetProcesses()
        If (proc.ProcessName = "EXCEL") then
    	MessageBox.Show("Excel is running.")
        End If
    Next


    Ashidacchi

    Wednesday, July 26, 2017 11:14 PM
  • Hi

    Thanks for your reply.

    I am looking at the event, that will be triggered when ever add-in is uninstalled from the Control Panel to check for the Process.

    Let me know, if you need clear explanation.

    Thanks

    Thursday, July 27, 2017 4:45 AM
  • Hi,
    As far as your thread, you wrote:
      [Title] Excel Add-in Uninstalling, check whether Excel is opened or not.
      [Body] If useful, don't know how to use and check for the Excel Process.
         If any sample code how this event will be working and to check for opened Excel Instance will be of helpful to me.
    So, I provided a sample code. But you want to know another. 

    I have no idea about the event that is fired by Program and features. 

    My alternative suggestion is:
    1. check registry periodically(e.g. in every one second) if your Add-In exists, while Excel process is running.
        registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    2. If your Add-In does not exist in this key, it could be considered that the Add-In has been uninstalled.

    Ashidacchi

    Thursday, July 27, 2017 6:12 AM
  • Hello Nihar,

    >>At the time of uninstalling the Add-in. I have to check, whether there is any opened Excel workbook.

    WorkbookAddinUninstall Event doesn't work for VSTO add-ins. It is for VBA add-ins like .xlam/.xla.

    Office object model doesn't provide any event when you uninstall the VSTO add-in. If you want to customize the install/uninstall process, it depends on your deployment method.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 27, 2017 7:00 AM
    Moderator
  • Hi

    Thanks for your Reply.

    I am using click once deployment.

    Any suggestion, how to work out for this deployment.

    Friday, July 28, 2017 3:50 AM
  • Hi

    Thanks for your Reply.

    I am using click once deployment.

    Any suggestion, how to work out for this deployment.

    If you are deploying by using ClickOnce, unfortuately, i think we are unable to customize its installer since VSTO project has its own customization installer.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 28, 2017 6:11 AM
    Moderator
  • Hi 

    what you said is correct. 

    When Excel is opened and the add-in is uninstalled.

    Excel will be working unless we close the excel.

    So how can we stop this, once the Add-in is uninstalled from the Machine.

    Any other way, that i can work around this. 

    Friday, July 28, 2017 6:55 AM
  • Hello,

    You could add a timer to check the registry key at intervals.

       public partial class ThisAddIn
        {
            Timer timer = new Timer();
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
               
                timer.Tick += Timer_Tick;
                timer.Interval = (1000) * (1);             
                timer.Enabled = true;                      
                timer.Start();
            }
    
            private void Timer_Tick(object sender, EventArgs e)
            {
                if (IsUninstall())
                {
                    MessageBox.Show("The add-in has been uninstalled");
                    timer.Stop();
                    timer.Enabled = false;
                }
            }
    
            public Boolean IsUninstall()
            {
                Microsoft.Win32.RegistryKey Key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Office\Excel\Addins\ExcelAddIn");
                if (Key != null)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
                timer = null;
                if(timer!=null)
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(timer);
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            
            #endregion
        }

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 28, 2017 7:37 AM
    Moderator
  • Thanks Celeste

    Your code helped me out to find a better fix for the Issue.

    Friday, July 28, 2017 12:52 PM
  • Thanks Celeste

    Your code helped me out to find a better fix for the Issue.

    Hello,

    If your issue has been resolved, please mark helpful post as answer to close this thread. If you have any other issue about this thread, please let me know. Thanks for your understanding.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 31, 2017 2:15 AM
    Moderator