473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Install Windows Service

Hi All,

I wrote a windows service with C# as below. But I can't install it with
installutil.exe. I got an error message "
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: File or assembly name windowsservice1, or
one of its dependencies, was not found.. "
I am new to C# environment. Any idea any clue will be appreciated. Thanks

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.ServiceProcess;

using System.Configuration.Install;

namespace WindowsService1

{

// Set 'RunInstaller' attribute to true.

[RunInstaller(true)]

public class MyProjectInstaller: Installer

{

private ServiceInstaller serviceInstaller1;

private ServiceProcessInstaller processInstaller;

public MyProjectInstaller() :base()

{

// Attach the 'Committed' event.

this.Committed += new InstallEventHandler(MyInstaller_Committed);

// Attach the 'Committing' event.

this.Committing += new InstallEventHandler(MyInstaller_Committing);

// Instantiate installers for process and services.

processInstaller = new ServiceProcessInstaller();

serviceInstaller1 = new ServiceInstaller();

// The services run under the system account.

processInstaller.Account = ServiceAccount.LocalSystem;

// The services are started manually.

serviceInstaller1.StartType = ServiceStartMode.Manual;

// ServiceName must equal those on ServiceBase derived classes.

serviceInstaller1.ServiceName = "WindowsService1";

// Add installers to collection. Order is not important.

Installers.Add(serviceInstaller1);

Installers.Add(processInstaller);

}

// Event handler for 'Committing' event.

private void MyInstaller_Committing(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committing Event occured.");

Console.WriteLine("");

}

// Event handler for 'Committed' event.

private void MyInstaller_Committed(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committed Event occured.");

Console.WriteLine("");

}

// Override the 'Install' method.

public override void Install(IDictionary savedState)

{

base.Install(savedState);

}

// Override the 'Commit' method.

public override void Commit(IDictionary savedState)

{

base.Commit(savedState);

}

// Override the 'Rollback' method.

public override void Rollback(IDictionary savedState)

{

base.Rollback(savedState);

}

}
[RunInstaller(true)]

public class Service1 : System.ServiceProcess.ServiceBase

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Service1()

{

// This call is required by the Windows.Forms Component Designer.

InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

// The main entry point for the process

static void Main()

{

System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add

// another service to this process, change the following line to

// create a second service object. For example,

//

// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(),
new MySecondUserService()};

//

ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };

System.ServiceProcess.ServiceBase.Run(ServicesToRu n);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

components = new System.ComponentModel.Container();

this.ServiceName = "WindowsService1";

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

/// <summary>

/// Set things in motion so your service can do its work.

/// </summary>

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

}
/// <summary>

/// Stop this service.

/// </summary>

protected override void OnStop()

{

// TODO: Add code here to perform any tear-down necessary to stop your
service.

}

}

}

Nov 17 '05 #1
2 7961
If I had to guess, I’d say that when you are trying to install the service
you are typing:

installutil.exe windowsservice1

not:

installutil.exe windowsservice1.exe

I say that because I had no problem building and installing this service,
and only when I dropped the .exe from the installation line did I get the
exception you did.

Brendan
"Fan Wang" wrote:
Hi All,

I wrote a windows service with C# as below. But I can't install it with
installutil.exe. I got an error message "
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: File or assembly name windowsservice1, or
one of its dependencies, was not found.. "
I am new to C# environment. Any idea any clue will be appreciated. Thanks

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.ServiceProcess;

using System.Configuration.Install;

namespace WindowsService1

{

// Set 'RunInstaller' attribute to true.

[RunInstaller(true)]

public class MyProjectInstaller: Installer

{

private ServiceInstaller serviceInstaller1;

private ServiceProcessInstaller processInstaller;

public MyProjectInstaller() :base()

{

// Attach the 'Committed' event.

this.Committed += new InstallEventHandler(MyInstaller_Committed);

// Attach the 'Committing' event.

this.Committing += new InstallEventHandler(MyInstaller_Committing);

// Instantiate installers for process and services.

processInstaller = new ServiceProcessInstaller();

serviceInstaller1 = new ServiceInstaller();

// The services run under the system account.

processInstaller.Account = ServiceAccount.LocalSystem;

// The services are started manually.

serviceInstaller1.StartType = ServiceStartMode.Manual;

// ServiceName must equal those on ServiceBase derived classes.

serviceInstaller1.ServiceName = "WindowsService1";

// Add installers to collection. Order is not important.

Installers.Add(serviceInstaller1);

Installers.Add(processInstaller);

}

// Event handler for 'Committing' event.

private void MyInstaller_Committing(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committing Event occured.");

Console.WriteLine("");

}

// Event handler for 'Committed' event.

private void MyInstaller_Committed(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committed Event occured.");

Console.WriteLine("");

}

// Override the 'Install' method.

public override void Install(IDictionary savedState)

{

base.Install(savedState);

}

// Override the 'Commit' method.

public override void Commit(IDictionary savedState)

{

base.Commit(savedState);

}

// Override the 'Rollback' method.

public override void Rollback(IDictionary savedState)

{

base.Rollback(savedState);

}

}
[RunInstaller(true)]

public class Service1 : System.ServiceProcess.ServiceBase

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Service1()

{

// This call is required by the Windows.Forms Component Designer.

InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

// The main entry point for the process

static void Main()

{

System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add

// another service to this process, change the following line to

// create a second service object. For example,

//

// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(),
new MySecondUserService()};

//

ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };

System.ServiceProcess.ServiceBase.Run(ServicesToRu n);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

components = new System.ComponentModel.Container();

this.ServiceName = "WindowsService1";

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

/// <summary>

/// Set things in motion so your service can do its work.

/// </summary>

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

}
/// <summary>

/// Stop this service.

/// </summary>

protected override void OnStop()

{

// TODO: Add code here to perform any tear-down necessary to stop your
service.

}

}

}


Nov 17 '05 #2
Thanks a lot. It is exactly as you said.

FAN

"Brendan Grant" <gr****@NOSPAMdahat.com> wrote in message
news:18**********************************@microsof t.com...
If I had to guess, I'd say that when you are trying to install the service
you are typing:

installutil.exe windowsservice1

not:

installutil.exe windowsservice1.exe

I say that because I had no problem building and installing this service,
and only when I dropped the .exe from the installation line did I get the
exception you did.

Brendan
"Fan Wang" wrote:
Hi All,

I wrote a windows service with C# as below. But I can't install it with
installutil.exe. I got an error message "
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: File or assembly name windowsservice1, or one of its dependencies, was not found.. "
I am new to C# environment. Any idea any clue will be appreciated. Thanks
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.ServiceProcess;

using System.Configuration.Install;

namespace WindowsService1

{

// Set 'RunInstaller' attribute to true.

[RunInstaller(true)]

public class MyProjectInstaller: Installer

{

private ServiceInstaller serviceInstaller1;

private ServiceProcessInstaller processInstaller;

public MyProjectInstaller() :base()

{

// Attach the 'Committed' event.

this.Committed += new InstallEventHandler(MyInstaller_Committed);

// Attach the 'Committing' event.

this.Committing += new InstallEventHandler(MyInstaller_Committing);

// Instantiate installers for process and services.

processInstaller = new ServiceProcessInstaller();

serviceInstaller1 = new ServiceInstaller();

// The services run under the system account.

processInstaller.Account = ServiceAccount.LocalSystem;

// The services are started manually.

serviceInstaller1.StartType = ServiceStartMode.Manual;

// ServiceName must equal those on ServiceBase derived classes.

serviceInstaller1.ServiceName = "WindowsService1";

// Add installers to collection. Order is not important.

Installers.Add(serviceInstaller1);

Installers.Add(processInstaller);

}

// Event handler for 'Committing' event.

private void MyInstaller_Committing(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committing Event occured.");

Console.WriteLine("");

}

// Event handler for 'Committed' event.

private void MyInstaller_Committed(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committed Event occured.");

Console.WriteLine("");

}

// Override the 'Install' method.

public override void Install(IDictionary savedState)

{

base.Install(savedState);

}

// Override the 'Commit' method.

public override void Commit(IDictionary savedState)

{

base.Commit(savedState);

}

// Override the 'Rollback' method.

public override void Rollback(IDictionary savedState)

{

base.Rollback(savedState);

}

}
[RunInstaller(true)]

public class Service1 : System.ServiceProcess.ServiceBase

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Service1()

{

// This call is required by the Windows.Forms Component Designer.

InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

// The main entry point for the process

static void Main()

{

System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add

// another service to this process, change the following line to

// create a second service object. For example,

//

// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};

//

ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

components = new System.ComponentModel.Container();

this.ServiceName = "WindowsService1";

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

/// <summary>

/// Set things in motion so your service can do its work.

/// </summary>

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

}
/// <summary>

/// Stop this service.

/// </summary>

protected override void OnStop()

{

// TODO: Add code here to perform any tear-down necessary to stop your
service.

}

}

}


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marina | last post by:
Hi, The windows service has reference to some custom DLL's, which are located in "subfolder/anotherfolder" relative to the service exe. There is a configuration file for the .exe which...
1
by: csheng | last post by:
I have a application to deliver now, and I am stuck. I developed a windows service, and I use intallutil to install. It works fine in development machine, when I copy the file to a windows 2003...
0
by: MarkM | last post by:
Hi there. Since upgrading to XP SP2 on my development box, I now compile the same windows service code and try to install it on a Windows 2000 server. Throws error "Access Is Denied". The...
2
by: Ant | last post by:
Does anyone have an example of how to install a windows service from .net code. I've seen PInvoke versions, but it should be able to be done using System.Configuration.Install.Installer as the...
2
by: Shani | last post by:
Could someone suggest me as to how to install an Windows Service in C#? I do not want to use InstallUtil as I need to pass a parameter, which is not possible. I do not want to use write an...
3
by: Jeremy S. | last post by:
On my dev machine (XP/Pro with VS.NET 2003) I have been developing a Windows Service and installing it on the local machine by opening the Visual Studio Command Prompt and then executing . Now I...
8
by: Stanley | last post by:
I have finished a Windows Service, now I'm trying to deploy the service to all my local computers. I want to ask if there is a fast way, rather then install it one by one? All answer would be...
2
by: Ronald S. Cook | last post by:
I just created a Windows Service. But now, how do I install it so that it shows up in my list of services? Thanks, Ron
1
by: =?Utf-8?B?Qi5BaGxzdGVkdA==?= | last post by:
Hi all, This is something that I have been toying with for about a week now. What I want to achieve is Install a Service with Customised parameters (using InstallUtil.exe) for User Name. Example...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.