Windows > Windows Forms Forums > ClickOnce and Setup & Deployment Projects > Problem with FolderBrowserDialog Box when called from Service Installer Class
Ask a questionAsk a question
 

AnswerProblem with FolderBrowserDialog Box when called from Service Installer Class

  • Thursday, November 05, 2009 10:27 AMdevensawant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Everyone,
    I have one windows form which takes backup of database while taking the backup it ask to select a destination folder by folderdialogbox and the mdf files is copied to the selected folder.
    This works fine, when i am taking a backup from project it self.
    Now what i want is when ever a user tries to uninstall a application then the system should ask him whether he wants to backup the database before uninstall, for this purpose i added a Service Installer class and overrided a OnBeforeUninstall method of Installer class in that i am showing the same form that was used to take a backup from prject. But in this case when a folderbrowserdialog box pops up it does not show folders it only shows a ok and cancel buttons Any ideas why I am running in this kind of behaviour. Any Suggessions will be appriciated

Answers

  • Thursday, November 05, 2009 7:52 PMPhilWilsonModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    The general reason this happens is that the MSI architecture is based on a UI sequence up front and a service running with the system account to do the actual install. It doesn't expect you to be showing Windows Forms UI from the Windows Installer service process. If you really really want to collect information like this you need a tool that provides an official way to offer UI at uninstall time.

    However, people try to make these things work.... so, I believe the issue is based on the fact that Windows UI requires a STA apartment, and the installer service isn't running with one. So you'd create a STA thread and then run your form on that thread.

    If I were you I wouldn't bother asking. If it's worth asking it's worth just doing the copy by default. Document that this happens during an uninstall.
    By the way, an upgrade using RemovePreviousVersions is also an uninstall of the old version of the product, so you'll see this dialog then even though the database file may not actually be getting removed anyway.
    Phil Wilson

All Replies

  • Thursday, November 05, 2009 7:52 PMPhilWilsonModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    The general reason this happens is that the MSI architecture is based on a UI sequence up front and a service running with the system account to do the actual install. It doesn't expect you to be showing Windows Forms UI from the Windows Installer service process. If you really really want to collect information like this you need a tool that provides an official way to offer UI at uninstall time.

    However, people try to make these things work.... so, I believe the issue is based on the fact that Windows UI requires a STA apartment, and the installer service isn't running with one. So you'd create a STA thread and then run your form on that thread.

    If I were you I wouldn't bother asking. If it's worth asking it's worth just doing the copy by default. Document that this happens during an uninstall.
    By the way, an upgrade using RemovePreviousVersions is also an uninstall of the old version of the product, so you'll see this dialog then even though the database file may not actually be getting removed anyway.
    Phil Wilson