C#一个windows服务项目如何生成和安装?
我用得是vs.net 2005
我先创建service工程,编好了代码。然后点击菜单栏-》项目-》添加新项,然后选择
"安装程序类"。
按f5最后弹个窗口说是要installutil安装,然后我用installutil安装,报错
Exception occurred while initializing the installation:
System.BadImageFormatException: The format of the file 'Info_center_sender_trigger.exe' is invalid..
怎么解决?
谢谢90。
然后出来两个.cs,修改它们成下面得的代码:
intaller1.cs
——————————————————————————————————
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
namespace WindowsService1
{
[RunInstaller(true)]
public partial class Installer1 : Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public Installer1()
{
InitializeComponent();
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
// Service will run under system account
processInstaller.Account = ServiceAccount.LocalSystem;
// Service will have Start Type of Manual
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "Infomation center sender trigger";
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
}
}
——————————————————————————————————————————
installer1.designer1.cs
namespace WindowsService1
{
partial class Installer1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
按f5,所有代码被锁定,然后弹了个对话窗口,大概说是要用intallutil安装完成;
我察看项目文件夹发现bin 目录和obj目录下都多了两个目录:debug和release,都只有release目录下有exe文件,我执行:
C:\Documents and Settings\Administrator>installutil "……\Projects\WindowsService1\WindowsService1\obj\Release\Info_center_sender_trigger.exe"
Microsoft (R) .NET Framework Installation utility Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Exception occurred while initializing the installation:
System.BadImageFormatException: The format of the file 'Info_center_sender_trigger.exe' is invalid..
点击_center_sender_trigger.exe执行,结果还是那个要求用installutil安装得信息。
怎么办呢?