简体   繁体   English

Windows服务无法通过MSI安装程序在几台计算机上安装

[英]Windows service fails to install through msi setup in few machines

I have developed an MSI setup with WiX, which includes a windows form application in c# .Net 2.0 framework and a windows service. 我使用WiX开发了一个MSI安装程序,其中包括c#.Net 2.0框架中的Windows窗体应用程序和Windows服务。 When I run the setup, it gets installed successfully in all win 7, but fails in few win 7 and all win 8 machines by showing the privilege error ("Product: mysetup -- Error 1920. Service 'service displayname' (servicename) failed to start. Verify that you have sufficient privileges to start system services.") while trying to start the service at installation. 当我运行安装程序时,它会通过显示特权错误(“产品:mysetup-错误1920。服务'service displayname'(服务名)失败),成功在所有win 7机器中成功安装,但在少数win 7和所有win 8机器中失败。尝试在安装时启动服务时,请确认您具有启动系统服务的足够特权。”) Then I created an App.config file inside my windows service project and according to this link I wrote the following line which helped the setup get installed in all the win 7 machines till now, but no luck for any win 8 machine. 然后,我在Windows服务项目中创建了一个App.config文件,并根据此链接编写了以下代码行,该文件帮助到目前为止在所有win 7机器上都安装了该安装程序,但是对于任何win 8机器都没有运气。

<runtime><generatePublisherEvidence enabled="false"/></runtime>

Regarding the service details, I have written the methods OnStart and OnStop inside my service. 关于服务细节,我已经在服务内部编写了方法OnStart和OnStop。 It actually starts the win form exe file at windows start-up. 它实际上在Windows启动时启动win窗体exe文件。 I have made the StartType property as Automatic at ServiceInstaller page and Account as LocalSystem at ServiceProcessInstaller page. 我在ServiceInstaller页面将StartType属性设置为Automatic,在ServiceProcessInstaller页面将AccountType设置为LocalSystem。 I have also written the codes below inside WiX to install my service. 我还在WiX内编写了以下代码来安装我的服务。

<ServiceInstall Id="ServiceInstaller" Type="ownProcess" Name="*******" DisplayName="******" Description="****** description" Start="auto" Account="LocalSystem" ErrorControl="ignore" Vital="yes" />
<ServiceControl Id="ServiceInstallerControl" Start="install" Stop="uninstall" Remove="uninstall" Name="******" Wait="yes" />

Presently, The setup and the windows service gets installed and runs fine in any win 7 machine, but fails in any win 8 and machine. 目前,安装程序和Windows服务已安装并在任何win 7机器上正常运行,但在任何win 8和机器上均失败。 Windows Event Viewer shows no detail but "msi setup fails". Windows事件查看器未显示任何详细信息,但“ msi安装失败”。

Please note that, I have not added any ClickOnce or Publisher certificate yet for my application. 请注意,我尚未为我的应用程序添加任何ClickOnce或Publisher证书。 I have planned to do it later, if that is not the reason for installation failure. 我计划以后再做,如果那不是安装失败的原因。 How can I solve this or get the error details or debug this any way? 如何解决此问题或获取错误详细信息或以任何方式进行调试? Please help. 请帮忙。

EDIT: 编辑:

PhilDW's answer is very important to note. PhilDW的答案非常重要。 My win form application (.exe file) which my service tries to run, does not show up as a GUI but yes it actually interacts with the desktop and to achieve that I have followed and implemented this link . 我的服务尝试运行的我的win表单应用程序(.exe文件)没有显示为GUI,但是是的,它实际上与桌面交互并实现了我所遵循并实现的此链接 This is working fine on win xp and win 7 as of now and the service starts the win from app successfully whenever a user logs on. 到目前为止,这在win xp和win 7上都可以正常工作,并且只要用户登录,该服务就会从应用程序成功启动win。 Not sure about win 8 or higher, hope this method does not get deprecated or blocked or barred by Microsoft Windows in higher versions for any security purpose (I mean, could this happen? what will be the solution then for interacting with desktop through LocalSystem windows service). 不确定win 8或更高版本,希望此方法不会出于更高的安全性目的而被更高版本的Microsoft Windows弃用,阻止或禁止(我的意思是,这会发生吗?那么通过LocalSystem窗口与桌面进行交互的解决方案是什么?服务)。

After Morten Frederiksen's answer I did the following. 在Morten Frederiksen回答之后,我做了以下工作。 On one Win 8 (32bit) pc, I checked inside Windows->Microsoft.Net->Framework folder which contains 4.0 and 4.5 but no 2.0/3.0/3.5 exactly as told by Morten. 在一台Win 8(32位)PC上,我检查了Windows-> Microsoft.Net-> Framework文件夹,该文件夹包含4.0和4.5,但完全没有Morten所说的2.0 / 3.0 / 3.5。 Now, my win form app already contains the supportedRuntime entry in its App.config file as suggested by Morten, but no luck with the installation. 现在,我的获胜表单应用程序已经按照Morten的建议在其App.config文件中包含了supportedRuntime条目,但是安装没有运气。 So I added the same ie 所以我添加了相同的ie

<configuration>
    <startup>
        <supportedRuntime version="v2.0.50727"/>
    </startup>
</configuration>

inside the App.config of my windows service (I think it's unnecessary) and ran the MSI after a rebuild, but the same thing happens, the installation rolls back displaying the same privilege error message. 在Windows服务的App.config中(我认为这是不必要的),并在重建后运行MSI,但是发生相同的事情,安装回滚并显示相同的特权错误消息。 Then I tried to run my win form app manually. 然后,我尝试手动运行赢表应用程序。 It shows the message "The app requires .Net framework 3.5. Would you like to download and install .Net framework 3.5 (2.0 and 3.0 included)". 它显示消息“该应用程序需要.Net framework 3.5。您是否要下载并安装.Net framework 3.5(包括2.0和3.0)”。 I clicked on "OK", it downloaded and installed the frameworks and ran the win form app .exe file successfully. 我单击“确定”,它下载并安装了框架,并成功运行了win窗体应用程序.exe文件。 Now that all frameworks are installed, I tried to reinstall my MSI and now it successfully gets installed and the service starts along with the app which actually does the desktop interaction now successfully. 现在已经安装了所有框架,我尝试重新安装MSI,现在它已成功安装,并且该服务与该应用程序一起启动,而该应用程序现在实际上已成功进行了桌面交互。

So, Morten Frederiksen's answer helped me solve my case. 因此,Morten Frederiksen的回答帮助我解决了案件。 It is clear now that in my case it is the absence of the required framework which caused the failure of the win form app which again caused the windows service to fail to start, which in turn caused the roll back of the MSI installation. 现在很明显,就我而言,正是由于缺少所需的框架才导致Win Form应用程序失败,这又导致Windows服务无法启动,进而导致MSI安装的回滚。

There are a few areas I'd look at, in no particular order. 我会按不特定的顺序查看一些区域。 I'm assuming your forms app attempts to show UI, among some other assumptions. 除其他一些假设外,我假设您的表单应用尝试显示UI。

You have wait=yes in the service startup. 您在服务启动中有wait = yes。 This causes Windows to wait until the service has started properly, the default wait time being 30 seconds. 这将导致Windows等待,直到服务正常启动为止,默认等待时间为30秒。 This means the service must get out of OnStart within 30 secs to show that it has in fact started ok. 这意味着该服务必须在30秒内退出OnStart,以表明它实际上已经可以正常启动。 If there is a delay in there because of what's going on, you may find a timing issue could randomly cause it to finish within 30 seconds or not. 如果由于发生了什么而导致延迟,您可能会发现计时问题可能会随机导致它在30秒内完成。

The second issue is probably more serious. 第二个问题可能更严重。 I do not believe you can start a Winforms app from a service for the same reason that local system services can no longer interact with the desktop - it exposes a system account to the user's desktop for shatter attacks. 我不认为您可以从服务启动Winforms应用程序,其原因与本地系统服务无法再与桌面进行交互的原因相同-它会将系统帐户暴露给用户的桌面,以进行粉碎攻击。 This may be strictly enforced in Windows 8, so the Winform process dies and has a downstream effect on the service, depending how it's coded. 在Windows 8中可能会严格执行此操作,因此Winform进程将终止,并对该服务产生下游影响,具体取决于其编码方式。 This is relevant https://msdn.microsoft.com/en-us/library/windows/desktop/ms683502(v=vs.85).aspx 这与https://msdn.microsoft.com/en-us/library/windows/desktop/ms683502(v=vs.85).aspx相关

Finally, even if you could interact with the desktop there's a potential timing issue after reboots. 最后,即使您可以与桌面进行交互,重启后也可能存在计时问题。 If your service starts up and fires off the Winforms app, then this can happen before anyone has logged on, unless your code waits for a logon, because services run all the time when there is no interactive user, so your service is starting a Winforms app that tries to access a non-existent desktop. 如果您的服务启动并从Winforms应用程序中启动,那么这可能会在任何人登录之前发生,除非您的代码等待登录,因为在没有交互用户的情况下服务一直在运行,因此您的服务正在启动Winforms。尝试访问不存在的桌面的应用程序。 I don't know if you've handled this area or not. 我不知道您是否处理过此区域。

I suggest you install your Winforms app and add a shortcut to the Start->Startup programs menu so that it starts when a user logs on. 我建议您安装Winforms应用程序并将快捷方式添加到“开始”->“启动程序”菜单中,以便在用户登录时启动。 Then it can establish communication with the running service. 然后,它可以与正在运行的服务建立通信。

My guess is that you don't have .NET 2.0/3.0/3.5 installed on the Windows 8 PCs. 我的猜测是您在Windows 8 PC上没有安装.NET 2.0 / 3.0 / 3.5。 By adding some configuration in your .config file you can enable .NET 2.0 applications on a system with only .NET 4.0/4.5 installed. 通过在.config文件中添加一些配置,可以在仅安装.NET 4.0 / 4.5的系统上启用.NET 2.0应用程序。

Here's how: https://msdn.microsoft.com/en-us/library/jj152935%28v=vs.110%29.aspx 方法如下: https : //msdn.microsoft.com/zh-cn/library/jj152935%28v=vs.110%29.aspx

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

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