views:

104

answers:

1

During install of a windows service (using class MyServiceInstaller : Installer, and ServiceInstaller and ServiceProcessInstaller) is there a way to force the installer to re-prompt the user for their user account info if they enter it incorrectly.

When the incorrect info is given the install throws an error 1001 message saying incorrect username or password, and then the install fails. I want to re-prompt the user until they get it correct, or they cancel out of the credential entry prompt.

Can I override OnBeforeRollback, and and tell it to retry?

    private ServiceInstaller _ServiceInstaller;
    private ServiceProcessInstaller _ProcessInstaller;

    public GBServiceInstaller()
    {
        InitializeComponent();
        _ServiceInstaller = new ServiceInstaller();
        _ProcessInstaller = new ServiceProcessInstaller();
        _ServiceInstaller.ServiceName = MyService.SERVICENAME;
        _ServiceInstaller.Description = MyService.SERVICEDESCRIPTION;
        _ServiceInstaller.StartType = ServiceStartMode.Manual;
        Installers.Add(_ServiceInstaller);
        Installers.Add(_ProcessInstaller);
+1  A: 

I think that when the installer is already about to begin the rollback it's probably too late. Rather, instead of having the installer fail, test that the username and password are correct before it even installs the actual service.

There are various ways to do this, one fairly easy way is to use the LogonUser API function as described here, and here is information about how to use PInvoke to call it from C#.

ho1