[python-win32] How to unload ShellExtension?

Mark Hammond mhammond at skippinet.com.au
Wed Jan 4 23:33:32 CET 2006


> I have previously asked about how to reload a ShellExtension during
> development. There a a few good suggestions like killnig the explorer
> process. Now I run into a bigger issue. When I uninstall (using
> innosetup), the process is still loaded and it lock up scores of DLLs.
> Killing explorer is probably too heavy handed for end users. So
> let me try
> one more time, is there anyway to positively tell explorer to
> unload a COM
> server?

Apart from Thomas's suggestion, I have managed to get inno to restart
explorer.  Our setup program detects if an old version of the shell
extension is installed and running, and if so, gives the user the choice of
restarting explorer to prevent the otherwise necessary reboot.

The inno script code we use is pasted below, but could be easily adapted to
any language.  Note however that when restarting in this way, Explorer
re-executes all "Startup" items, whereas if explorer is "killed" and
restarted, this re-processing of startup items does *not* happen.

Cheers,

Mark

    { send WM_QUIT to explorer - 18 == WM_QUIT}
    hwnd := FindWindowByClassName('Progman');
    PostMessage(hwnd, 18, 0, 0);
    retryAttempt := 0;
    { wait a while for it to exit  - 10 seconds, checking twice/sec }
    for retryAttempt := 1 to 20 do begin
      sleep(500);
      if FindWindowByClassName('Progman') = 0 then break
    end;
    sleep(2000);
    { explorer is dead - restart it (SW_SHOW=5) }
    InstExec('explorer.exe', '', '', False, False, 5, errCode);
    { Now a few seconds to actually start - if we don't wait for this,
      then we may write the RunOnce keys before it has, causing
      explorer to process them as we are still installing (or just
finished).
      Explorer processes the 'RunOnce' etc entries before creating its main
window,
    }
    for retryAttempt := 1 to 20 do begin
      sleep(500);
      if FindWindowByClassName('Progman') <> 0 then break
    end;
    { OK, explorer is back up }



More information about the Python-win32 mailing list