简体   繁体   English

使用服务安装msi,如果输入的凭据不正确,是否有办法强制安装程序重新提示用户

[英]With a Service install msi, Is there a way to force the installer to re-prompt the user if credentials were entered incorrectly

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. 在安装Windows服务(使用类MyServiceInstaller:Installer,ServiceInstaller和ServiceProcessInstaller)期间,有一种方法可以强制安装程序重新提示用户输入错误的用户帐户信息。

When the incorrect info is given the install throws an error 1001 message saying incorrect username or password, and then the install fails. 当给出不正确的信息时,安装会抛出错误1001消息,说明用户名或密码不正确,然后安装失败。 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? 我可以覆盖OnBeforeRollback,并告诉它重试吗?

    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);

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#. 有多种方法可以做到这一点,一个很简单的方法是使用LogonUser描述API函数在这里 ,并在这里是如何使用的PInvoke从C#调用它的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM