use*_*128 11 windows service wix
我有以下WiX项目来安装我的服务:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="GUID" Name="SetupWinService" Language="1049"
Version="1.0.0.0" Manufacturer="SetupWinService"
UpgradeCode="GUID">
<Package InstallerVersion="200" Compressed="yes"
Languages="1049" SummaryCodepage="1251"
InstallPrivileges="elevated"/>
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="WinService" Name="My Windows Service">
</Directory>
</Directory>
</Directory>
<DirectoryRef Id="WinService">
<Component Id="WinServiceInstallation" Guid="GUID">
<File Id="ClientService.exe"
Name="ClientService.exe"
Source="...\ClientService.exe"
Vital="yes" KeyPath="yes" DiskId="1"/>
<File Id="App.config"
Name="App.config"
Source="...\App.config"
Vital="yes" KeyPath="no" DiskId="1"/>
<!--And some DLLs here-->
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Vital="yes"
Name="WcfServiceHost"
DisplayName="WcfServiceHost"
Description="Hosts Wcf Service"
Start="auto"
Account="LocalSystem"
ErrorControl="ignore"
Interactive="no">
</ServiceInstall>
<ServiceControl Id="StartService" Name="WcfServiceHost"
Start="install" Stop="uninstall" Remove="uninstall"
Wait="yes" />
</Component>
</DirectoryRef>
<Feature Id="Complete" Title="SetupWinService" Level="1">
<ComponentRef Id="WinServiceInstallation" />
<ComponentGroupRef Id="Product.Generated" />
</Feature>
</Product>
</Wix>
Run Code Online (Sandbox Code Playgroud)
我可以安装我的服务,但安装后无法启动它.它说:
服务无法启动.验证您是否具有足够的权限来启动系统服务.
但我以管理员身份运行安装程序(Windows 7 Professional)并禁用UAC.此外,我可以通过命令提示符安装和运行instalutil.exe服务(我的服务项目包括Installer类的实现,一般根据本文标记),在这种情况下一切正常.
如果我将ServiceControl元素的Wait ="yes"替换为"no",则服务安装没有错误,但它不会启动.在这种情况下,我也无法手动启动服务,因为服务启动并立即停止,并显示消息"本地计算机上的服务已启动然后停止.如果没有工作要做,某些服务会自动停止".
我在互联网上搜索了这个问题,但我找不到任何解决方案.
我如何解决它?
这是我的Installer类的代码:
[RunInstaller(true)]
public class ProjectInstaller : Installer
{
private ServiceProcessInstaller serviceProcessInstaller;
private ServiceInstaller serviceInstaller;
public ProjectInstaller()
{
this.serviceProcessInstaller = new ServiceProcessInstaller();
this.serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
this.serviceProcessInstaller.Username = null;
this.serviceProcessInstaller.Password = null;
this.serviceInstaller = new ServiceInstaller();
this.serviceInstaller.ServiceName = "ClientServicesHost";
this.serviceInstaller.StartType = ServiceStartMode.Automatic;
this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
this.AfterInstall +=
new InstallEventHandler(ProjectInstaller_AfterInstall);
}
void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
{
ServiceController sc = new ServiceController("ClientServicesHost");
sc.Start();
}
}
Run Code Online (Sandbox Code Playgroud)
我的Windows服务:
class WindowsClientService : ServiceBase
{
public ServiceHost serviceHost = null;
public WindowsClientService()
{
this.ServiceName = "WcfServiceHost";
}
public static void Main()
{
ServiceBase.Run(new WindowsClientService());
}
protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
}
// Create a ServiceHost for WcfClientService type
// and provide the base address.
serviceHost = new ServiceHost(typeof(WcfClientService));
// Open the ServiceHost to create listeners
// and start listening for messages.
serviceHost.Open();
}
protected override void OnStop()
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost = null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我被指出我服务的原因会自动停止 - 它在启动后什么都不做.是真的吗?我的服务创建了听众并开始倾听 - 是"什么都不做"?
小智 7
我使用WiX 3.7.821.0和我的服务遇到了同样的问题.它安装了一段时间,同样令人讨厌的"服务无法启动.验证你有足够的权限启动系统服务"出现.
我尝试了很多,但最后的事情是使用两个部分<ServiceControl>
而不是试图在一个部分中填充所有部分.一个用于开始,一个用于停止.现在服务开始很好.
这不起作用:
<ServiceControl Id="StartService"
Start="install"
Stop="both"
Remove="uninstall"
Name="MyService"
Wait="yes" />
Run Code Online (Sandbox Code Playgroud)
这有效:
<ServiceControl Id="ServiceControl_Start"
Name="MyService"
Start="install"
Wait="no" />
<ServiceControl Id="ServiceControl_Stop"
Name="MyService"
Stop="both"
Remove="uninstall"
Wait="yes" />
Run Code Online (Sandbox Code Playgroud)
小智 6
找了好久的答案,终于解决了!
保持与 ServiceInstall 名称相同的 ServiceControl 名称。
结果:
<?xml version="1.0" encoding="utf-8"?>
<?define ProductVersion = "1.0.0"?>
<?define ProductUpgradeCode = "{E8DFD614-41F6-4592-AD7A-27EA8A49C82E}"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="*" UpgradeCode="$(var.ProductUpgradeCode)"
Name="Eyes Relax"
Version="$(var.ProductVersion)"
Manufacturer="Ourdark"
Language="1033">
<Package Manufacturer="Ourdark" InstallerVersion="100" Languages="1033" Compressed="yes" />
<Media Id="1" Cabinet="WHSDiskManagement.1.1.0.0.cab" EmbedCab="yes" />
<Property Id="WHSLogo">1</Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="WHS" Name="Eyes Relax">
<Component Id="EyesRelax" Guid="{78534F5E-FC72-49E6-AF11-4F2068EA7571}">
<File Id="RelaxEyes.exe.config"
Name="RelaxEyes.exe.config"
Source="RelaxEyes\bin\Debug\RelaxEyes.exe.config"
Vital="yes"
KeyPath="no"
DiskId="1"/>
<File Id="RelaxEyes.exe"
Name="RelaxEyes.exe"
Source="RelaxEyes\bin\Debug\RelaxEyes.exe"
Vital="yes"
KeyPath="yes"
DiskId="1"/>
<ServiceInstall
Id="ServiceInstaller"
Type="ownProcess"
Vital="yes"
Name="Eyes Relax"
DisplayName="Eyes Relax"
Description="Eyes Relax"
Start="auto"
Account="NT AUTHORITY\LocalService"
ErrorControl="ignore"
Interactive="no">
</ServiceInstall>
<ServiceControl Id="StartService"
Start="install"
Stop="both"
Remove="uninstall"
Name="Eyes Relax"
Wait="yes" />
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="WHSDiskManagement" Level="1">
<ComponentRef Id="EyesRelax" />
</Feature>
</Product>
</Wix>
Run Code Online (Sandbox Code Playgroud)
小智 5
我有同样的错误,在我的情况下KeyPath='yes' Vital="yes"
,我的文件元素丢失了.
这是我的组件定义:
<Component Id="ComponentName"
Guid="3aa1d5a5-28f0-4753-8e4b-a7ac0848d8be" >
<File Id='ServiceFile'
Name='Service.exe'
DiskId='1'
Source='bin\Service.exe'
KeyPath='yes'
Vital="yes"/>
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Name="Service"
DisplayName="Service"
Description="A Service"
Start="auto"
ErrorControl="normal"
/>
<ServiceControl Id="ServiceControl"
Start="install"
Stop="both"
Remove="uninstall"
Name="Service"
Wait="yes" />
</Component>
Run Code Online (Sandbox Code Playgroud)
嗯,大约一年半后我又回到了这个项目。并尝试重新编译它并再次启动该服务。它有效!
所发生的变化是我将 clientaccesspolicy.xml 添加到我的服务中,并与我的服务一起运行policyServiceHost(WebServiceHost 类型)。但我认为这并不重要,因为它与我的应用程序内部相关 - 而不是与服务启动相关。
所以我尝试了很多变体,例如:
1) this.serviceProcessInstaller.Username = null;
或者
this.serviceProcessInstaller.Username = @"NT AUTHORITY\SYSTEM";
2) 两个或单个服务控制部分。
3)停止=“两者”
或者
停止=“卸载”
现在一切正常!!!
我不知道发生了什么事。我只是将其留给某种类型的错误或系统的某些奇怪配置或其他不允许我之前自动启动服务的东西。但现在一切正常。
换句话说,我没有找出我的服务无法自动启动的原因是什么。这是关于“足够的特权”(参见第一篇文章),但即使现在对我来说还不够清楚。
只有一件事。如果我在卸载服务时使用两个 ServiceControl 部分,则会出现一个警告窗口 (Windows 7),并提示自动关闭应用程序(服务)等。所以我只是接受并且服务卸载得很好。但是,如果我仅使用一个 ServiceControl 部分(如第一篇文章中的示例所示),则不会出现警告窗口。同样,它与 1) 和 3) 点组合没有关系。
归档时间: |
|
查看次数: |
15510 次 |
最近记录: |