简体   繁体   English

Windows服务的自定义操作安装程序

[英]Custom Actions Installer for Windows Service

I have a windows service which I silent install using msiexec.exe and I am passing the username and password for the "Set Service Login" 我有一个Windows服务,我使用msiexec.exe进行了静默安装,并且正在传递“设置服务登录名”的用户名和密码

The Service is successfully installing but upon Starting the service I am receiving "error 1069: The service did not start due to logon problems"my logon account is administrator and I have tested that when I manually install using the same msi file and start the service it is starting successfully, I am stuck and need some ideas and guidance of what I am missing. 服务已成功安装,但是启动服务后,我收到“错误1069:由于登录问题而导致服务未启动”,我的登录帐户是管理员,并且已经测试了使用相同的msi文件手动安装并启动服务时的情况。它开始成功,我被困住了,需要一些关于我所缺少的东西的想法和指导。

here is my overriden method from Installer Class. 这是我从安装程序类重写的方法。

 public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);

        var userName = Context.Parameters["USERNAME"];
        var password = Context.Parameters["PASSWORD"];
        if (!string.IsNullOrWhiteSpace(userName) && userName.ToLower() != "admin")
        {
            CustomInstallerParameters customParameters = new CustomInstallerParameters(Context);

            SaveCustomParametersInStateSaverDictionary(stateSaver, customParameters);
        }
        else
        {
            Context.Parameters.Remove("USERNAME");
            Context.Parameters.Remove("PASSWORD");
        }
    }

TIA. TIA。

Most likely, different decade, same problem.... (SeServiceLogonRight) 最可能的是,不同的十年,同样的问题。...(SeServiceLogonRight)

http://iswix.com/2008/09/22/different-year-same-problem/ http://iswix.com/2008/09/22/different-year-same-problem/

FWIW, I wasn't a big WiX user yet back then (I was merely dabbling at that point) but there are some real gems in the comments from my Matthew Rowan. FWIW,那时我还不是WiX的大用户(当时我只是涉足),但是我的Matthew Rowan的评论中有一些真正的宝石。 He is correct... all of this gets WAY easier if you are using WiX. 他是正确的...如果您使用的是WiX,所有这些都将变得更加容易。

For example you can follow this tutorial: 例如,您可以按照本教程进行操作:

https://github.com/iswix-llc/iswix-tutorials https://github.com/iswix-llc/iswix-tutorials

This creates a windows service running as SYSTEM. 这将创建一个以SYSTEM身份运行的Windows服务。 Add a reference to the WiXUtil extension and namespace and author a User element with the LogonAsService right set and your all set. 添加对WiXUtil扩展名和名称空间的引用,并创建具有LogonAsService权限和所有设置的User元素。

FWIW, my only concern with all this is that MSI needs property persistence if you don't want a repair to come by and corrupt the username and password. FWIW,我对这一切的唯一担心是,如果您不希望进行修复并破坏用户名和密码,则MSI需要属性持久性。 Property persistence is pretty easy to remember ( See: http://robmensching.com/blog/posts/2010/5/2/the-wix-toolsets-remember-property-pattern/ ) but the problem is providing enough encryption to not expose the account. 属性持久性非常容易记住(请参阅: http : //robmensching.com/blog/posts/2010/5/2/the-wix-toolsets-remember-property-pattern/ ),但问题是提供了足够的加密而没有暴露帐户。

It's for the reason I typically suggest just running as NetworkService or SYSTEM and grant the computer object rights in a domain. 因此,我通常建议仅以NetworkService或SYSTEM身份运行并在域中授予计算机对象权限。 An alternative is to have the installer create the service account and randomize the password on each repair so you don't have to persist it. 一种替代方法是让安装程序创建服务帐户并在每次维修时随机分配密码,因此您不必保留该密码。

It appears that you are using a Visual Studio setup project, and most likely also using one of the TextBoxes dialogs to collect the input. 似乎您正在使用Visual Studio安装项目,并且很可能还使用了TextBoxes对话框之一来收集输入。

You can't silently pass these parameters on the command line because Visual Studio generates custom actions to clear them (and I don't know why). 您不能在命令行上静默传递这些参数,因为Visual Studio会生成自定义操作来清除它们(我不知道为什么)。 In a silent install Windows runs just the InstallExecuteSequence, and if you look in there with (for example) Orca you'll see custom actions such as "CustomTextA_SetProperty_EDIT1" that clear the values. 在无提示安装中,Windows仅运行InstallExecuteSequence,并且如果您使用(例如)Orca进行查看,您会看到清除值的自定义操作,例如“ CustomTextA_SetProperty_EDIT1”。 To state the obvious, the values you currently get will be blank, and you could verify this by logging the values somewhere. 为了说明清楚,当前获得的值将为空白,您可以通过将值记录在某处来验证这一点。

So a starting point to getting this to work is to use Orca to delete those custom action calls in the InstallExecuteSequence table. 因此,使其生效的起点是使用Orca删除InstallExecuteSequence表中的那些自定义操作调用。

After that, there is a potential problem that the values won't make it to your custom action because they are not secured, so in the Property table you'd need to add those property names to the SecureCustomProperties list, semi-colon delimited (EDIT1;EDIT2 and so on). 此后,存在一个潜在的问题,因为这些值不受保护,因此这些值无法用于您的自定义操作,因此您需要在“属性”表中将这些属性名称添加到以分号分隔的SecureCustomProperties列表中( EDIT1; EDIT2等)。

Visual Studio setup projects aren't good at any of this, and something like WiX would be better because no code is required to install, start or stop services, or configure them with an account. Visual Studio安装项目不能很好地解决这些问题,而WiX之类的项目会更好,因为不需要任何代码即可安装,启动或停止服务或使用帐户配置它们。

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

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