启动时服务失败 [英] Service Fails on Start

查看:72
本文介绍了启动时服务失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我在创建Windows服务时遇到问题

监视事件的映射驱动器(使用FileSystemEventHandler)。

服务符合但无法启动:


本地计算机上的XMLWatcher服务已启动然后停止。

如果没有工作要做,某些服务会自动停止。

例如,Preformance Logs and Alerts服务。


如果我将文件夹指向

,则服务开始没有问题我的本地C盘,它作为控制台应用程序或Windows应用程序监控

映射的网络驱动器没有问题。


任何帮助将不胜感激。


安装程序:


private void InitializeComponent()

{

这个。 serviceProcessInstaller1 = new

System.ServiceProcess.ServiceProcessInstaller();

this.serviceInstaller1 = new

System.ServiceProcess.Service安装程序();

//

// serviceProcessInstaller1

//

System.ServiceProcess.ServiceControllerPermissionA ccess

this.serviceProcessInstaller1.Account =

System.ServiceProcess.ServiceAccount.User;

this.serviceProcessInstaller1.Password =" XXXXXXXX";

this.serviceProcessInstaller1.Username =" MyUserName";

//

// serviceInstaller1

//

this.serviceInstaller1.ServiceName =" XMLWatcher";

//

// ProjectInstaller

//

this.Installers.AddRange(new

System.Configuration.Install.Installer [] {

this.serviceProcessInstaller1,

this.serviceInstaller1});


}

Main Intializer

private void IntializeFileSystemWatcher()

{

//为XML文件创建文件系统观察器

fsWatcher = new System.IO.FileSystemWatcher(" Y:\\ \"," * .xml");

//为新的XML文件添加事件处理程序并更改现有的XML

文件。

fsWatcher.Changed + = new FileSystemEventHandler(OnXMLFileChanged);

fsWatcher.Created + = new FileSystemEventHandler(OnXMLFileCreated);


//开始观看。

fsWatcher.EnableRaisingEvents = true;

fsWatcher1.EnableRaisingEvents = true;

}

Currently I am having a problem creating a windows service that
monitors a mapped drive for events (using the FileSystemEventHandler).
The service complies but fails to start:

"The XMLWatcher service on Local Computer started and then stopped.
Some services stop automatically if they have no work to do, for
example, the Preformance Logs and Alerts service."

The Service has no problem starting if i point the folder to be
monitored to my local C drive, and it had no problem monitoring the
mapped network drive as a console app or windows app.

Any Help would be greatly appreciated.

Installer:

private void InitializeComponent()
{
this.serviceProcessInstaller1 = new
System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new
System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1
//
System.ServiceProcess.ServiceControllerPermissionA ccess
this.serviceProcessInstaller1.Account =
System.ServiceProcess.ServiceAccount.User;
this.serviceProcessInstaller1.Password = "XXXXXXXX";
this.serviceProcessInstaller1.Username = "MyUserName";
//
// serviceInstaller1
//
this.serviceInstaller1.ServiceName = "XMLWatcher";
//
// ProjectInstaller
//
this.Installers.AddRange(new
System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1});

}
Main Intializer
private void IntializeFileSystemWatcher()
{
//Create File System Watcher for XML files
fsWatcher=new System.IO.FileSystemWatcher("Y:\\","*.xml");
// Add event handlers for new XML files and change of existing XML
files.
fsWatcher.Changed += new FileSystemEventHandler(OnXMLFileChanged);
fsWatcher.Created += new FileSystemEventHandler(OnXMLFileCreated);

// Begin watching.
fsWatcher.EnableRaisingEvents = true;
fsWatcher1.EnableRaisingEvents = true;
}

推荐答案

我的经验是,启动和停止的服务正在抛出

例外。检查事件日志以查看是否有任何错误来自

您的服务。


此外,通常更容易/更好地编写服务一个库(dll)和

然后使用控制台或其他应用程序进行测试,然后只需从服务中调用

到dll中。这并没有消除服务中出错的可能性,但它减少了它们,它使开发变得更加容易。


--Brian


Jasonkimberson写道:
My experience has been that services that start and stop are throwing
exceptions. Check the event log to see if there are any events with errors from
your service.

Also, it is usually easier / better to write the service in a library (dll) and
then test that using console or other applications, and then just make calls
into the dll from the service. This doesn''t eliminate the chance of errors in
the service, but it reduces them and it makes development much easier.

--Brian

Jasonkimberson wrote:
目前我在创建一个监视映射驱动器事件的Windows服务时遇到问题(使用FileSystemEventHandler)。服务符合但无法启动:

本地计算机上的XMLWatcher服务已启动然后停止。
如果没有工作要做,某些服务会自动停止例如,Preformance Logs and Alerts服务。

如果我将要监控的文件夹指向我的本地C盘,那么服务启动没有问题,它没有问题监控
映射的网络驱动器作为控制台应用程序或Windows应用程序。

任何帮助将不胜感激。

安装程序:

private void InitializeComponent()
{
this.service ProcessInstaller1 = new
System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new
System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1 < /> //
System.ServiceProcess.ServiceControllerPermissionA ccess
this.serviceProcessInstaller1.Account =
System.ServiceProcess.ServiceAccount.User;
this.serviceProcessInstaller1.Password =" XXXXXXXX" ;;
this.serviceProcessInstaller1.Username =" MyUserName";
//
// serviceInstaller1
// this /serviceInstaller1.ServiceName =" XMLWatcher" ;
//
// ProjectInstaller
//
this.Installers.AddRange(新的
System.Configuration.Install.Installer [] {
这个.serviceProcessInstaller1,
this.serviceInstaller1});

}

Main Intializer

private void IntializeFileSystemWatcher()
{
//创造e XML文件的文件系统观察器
fsWatcher = new System.IO.FileSystemWatcher(Y:\\,*。xml);
//为新的事件添加事件处理程序XML文件和现有XML文件的更改。
fsWatcher.Changed + = new FileSystemEventHandler(OnXMLFileChanged);
fsWatcher.Created + = new FileSystemEventHandler(OnXMLFileCreated);
//开始观看。
fsWatcher.EnableRaisingEvents = true;
fsWatcher1.EnableRaisingEvents = true;
}
Currently I am having a problem creating a windows service that
monitors a mapped drive for events (using the FileSystemEventHandler).
The service complies but fails to start:

"The XMLWatcher service on Local Computer started and then stopped.
Some services stop automatically if they have no work to do, for
example, the Preformance Logs and Alerts service."

The Service has no problem starting if i point the folder to be
monitored to my local C drive, and it had no problem monitoring the
mapped network drive as a console app or windows app.

Any Help would be greatly appreciated.

Installer:

private void InitializeComponent()
{
this.serviceProcessInstaller1 = new
System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new
System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1
//
System.ServiceProcess.ServiceControllerPermissionA ccess
this.serviceProcessInstaller1.Account =
System.ServiceProcess.ServiceAccount.User;
this.serviceProcessInstaller1.Password = "XXXXXXXX";
this.serviceProcessInstaller1.Username = "MyUserName";
//
// serviceInstaller1
//
this.serviceInstaller1.ServiceName = "XMLWatcher";
//
// ProjectInstaller
//
this.Installers.AddRange(new
System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1});

}
Main Intializer
private void IntializeFileSystemWatcher()
{
//Create File System Watcher for XML files
fsWatcher=new System.IO.FileSystemWatcher("Y:\\","*.xml");
// Add event handlers for new XML files and change of existing XML
files.
fsWatcher.Changed += new FileSystemEventHandler(OnXMLFileChanged);
fsWatcher.Created += new FileSystemEventHandler(OnXMLFileCreated);

// Begin watching.
fsWatcher.EnableRaisingEvents = true;
fsWatcher1.EnableRaisingEvents = true;
}



重读帖子我认为这是一个安全/权利问题。如果它对C:\运行
但不对网络驱动器,则表示安全。


我自己没有使用它但是当你的服务运行时,你可能会考虑模仿另一个用户。我看到你试图设置一个用户名和密码,但

我不确定这是服务运行的原因。

尝试查看System.Security.Principal.WindowsIdentity类''

模拟方法。


--Brian

Brian佩尔顿写道:
Rereading the post I''m thinking it is a security / rights issue. If it works
against C:\ but not against a network drive, that would point to security.

I haven''t used it myself but you might look into impersonating another user when
your service runs. I see that you''re trying to set a username and password but
I''m not sure that that is what the service is running under.

Try looking into the System.Security.Principal.WindowsIdentity class''
Impersonate method.

--Brian
Brian Pelton wrote:
我的经验是,开始和停止的服务都在抛出异常。检查事件日志,看看您的服务是否有任何错误事件。

此外,在库中编写服务通常更容易/更好
(dll )然后使用控制台或其他应用程序测试,然后
只是从服务调用dll。这并没有消除服务中出错的可能性,但它减少了它们,使得开发变得更加容易。

- 布莱恩

My experience has been that services that start and stop are throwing
exceptions. Check the event log to see if there are any events with
errors from your service.

Also, it is usually easier / better to write the service in a library
(dll) and then test that using console or other applications, and then
just make calls into the dll from the service. This doesn''t eliminate
the chance of errors in the service, but it reduces them and it makes
development much easier.

--Brian

Jasonkimberson wrote:
目前我在创建一个监视映射驱动器事件的Windows服务时遇到了问题(使用FileSystemEventHandler)。
服务符合但无法启动:

本地计算机上的XMLWatcher服务已启动然后停止。
如果没有工作要做,某些服务会自动停止。
例如, 性能日志和警报服务。

如果我将要监控的文件夹指向我的本地C驱动器,则服务启动没有问题,并且监控
映射网络驱动器作为控制台应用程序或Windows应用程序。

任何帮助将不胜感激。

安装程序:

private void InitializeComponent( )
{
is.serviceProcessInstaller1 = new
System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new
System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1
// System.ServiceProcess.ServiceControllerPermissionA ccess
this.serviceProcessInstaller1.Account =
System.ServiceProcess.ServiceAccount.User;
this.serviceProcessInstaller1.Password =" ; XXXXXXXX" ;;
this.serviceProcessInstaller1.Username =" MyUserName";
//
// serviceInstaller1
//
this.serviceInstaller1.ServiceName =" XMLWatcher" ;;
//
// ProjectInstaller
//
this.Installers.AddRange(new
System.Configuration.Install.Installer [] {
this.serviceProcessInstalle r1,
this.serviceInstaller1});

}

Main Intializer

private void IntializeFileSystemWatcher()
{
//为XML文件创建文件系统监视器
fsWatcher = new System.IO.FileSystemWatcher(" Y:\\"," * .xml");
//为新的XML文件添加事件处理程序并更改现有的XML
文件。
fsWatcher.Changed + = new
FileSystemEventHandler(OnXMLFileChanged);
fsWatcher.Created + =新的
FileSystemEventHandler(OnXMLFileCreated);

//开始观看。
fsWatcher.EnableRaisingEvents = true;
fsWatcher1.EnableRaisingEvents = true;
}
Currently I am having a problem creating a windows service that
monitors a mapped drive for events (using the FileSystemEventHandler).
The service complies but fails to start:

"The XMLWatcher service on Local Computer started and then stopped.
Some services stop automatically if they have no work to do, for
example, the Preformance Logs and Alerts service."

The Service has no problem starting if i point the folder to be
monitored to my local C drive, and it had no problem monitoring the
mapped network drive as a console app or windows app.

Any Help would be greatly appreciated.

Installer:

private void InitializeComponent()
{
this.serviceProcessInstaller1 = new
System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new
System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1
//
System.ServiceProcess.ServiceControllerPermissionA ccess
this.serviceProcessInstaller1.Account =
System.ServiceProcess.ServiceAccount.User;
this.serviceProcessInstaller1.Password = "XXXXXXXX";
this.serviceProcessInstaller1.Username = "MyUserName";
//
// serviceInstaller1
//
this.serviceInstaller1.ServiceName = "XMLWatcher";
//
// ProjectInstaller
//
this.Installers.AddRange(new
System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1});

}
Main Intializer
private void IntializeFileSystemWatcher()
{
//Create File System Watcher for XML files
fsWatcher=new System.IO.FileSystemWatcher("Y:\\","*.xml");
// Add event handlers for new XML files and change of
existing XML
files.
fsWatcher.Changed += new
FileSystemEventHandler(OnXMLFileChanged);
fsWatcher.Created += new
FileSystemEventHandler(OnXMLFileCreated);

// Begin watching.
fsWatcher.EnableRaisingEvents = true;
fsWatcher1.EnableRaisingEvents = true;
}



知道映射驱动器无效的原因吗?


系统事件日志:

以下信息是活动的一部分:服务不能是
开始了。 System.ArgumentException:目录名Y:\无效。

在System.IO.FileSystemWatcher..ctor(String path,String filter)

在XMLFileWatcher.XMLWatcher .IntializeFileSystemWatch er()in

c:\documents and settings\desktop\service\xmlfilewatcher.cs:line 147

at XMLFileWatcher.XMLWatcher.OnStart(String [] args)在c:\documents

和settings \desktop\service\xmlfilewatcher.cs:第610行

在System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback

Any idea why the mapped drive is invalid?

System Events Log:
The following information is part of the event: Service cannot be
started. System.ArgumentException: The directory name Y:\ is invalid.
at System.IO.FileSystemWatcher..ctor(String path, String filter)
at XMLFileWatcher.XMLWatcher.IntializeFileSystemWatch er() in
c:\documents and settings\desktop\service\xmlfilewatcher.cs:line 147
at XMLFileWatcher.XMLWatcher.OnStart(String[] args) in c:\documents
and settings\desktop\service\xmlfilewatcher.cs:line 610
at System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback


这篇关于启动时服务失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆