473,624 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Service Fails on Start

Currently I am having a problem creating a windows service that
monitors a mapped drive for events (using the FileSystemEvent Handler).
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 InitializeCompo nent()
{
this.servicePro cessInstaller1 = new
System.ServiceP rocess.ServiceP rocessInstaller ();
this.serviceIns taller1 = new
System.ServiceP rocess.ServiceI nstaller();
//
// serviceProcessI nstaller1
//
System.ServiceP rocess.ServiceC ontrollerPermis sionAccess
this.servicePro cessInstaller1. Account =
System.ServiceP rocess.ServiceA ccount.User;
this.servicePro cessInstaller1. Password = "XXXXXXXX";
this.servicePro cessInstaller1. Username = "MyUserName ";
//
// serviceInstalle r1
//
this.serviceIns taller1.Service Name = "XMLWatcher ";
//
// ProjectInstalle r
//
this.Installers .AddRange(new
System.Configur ation.Install.I nstaller[] {
this.servicePro cessInstaller1,
this.serviceIns taller1});

}
Main Intializer
private void IntializeFileSy stemWatcher()
{
//Create File System Watcher for XML files
fsWatcher=new System.IO.FileS ystemWatcher("Y :\\","*.xml");
// Add event handlers for new XML files and change of existing XML
files.
fsWatcher.Chang ed += new FileSystemEvent Handler(OnXMLFi leChanged);
fsWatcher.Creat ed += new FileSystemEvent Handler(OnXMLFi leCreated);

// Begin watching.
fsWatcher.Enabl eRaisingEvents = true;
fsWatcher1.Enab leRaisingEvents = true;
}

Nov 17 '05 #1
14 7212
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:
Currently I am having a problem creating a windows service that
monitors a mapped drive for events (using the FileSystemEvent Handler).
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 InitializeCompo nent()
{
this.servicePro cessInstaller1 = new
System.ServiceP rocess.ServiceP rocessInstaller ();
this.serviceIns taller1 = new
System.ServiceP rocess.ServiceI nstaller();
//
// serviceProcessI nstaller1
//
System.ServiceP rocess.ServiceC ontrollerPermis sionAccess
this.servicePro cessInstaller1. Account =
System.ServiceP rocess.ServiceA ccount.User;
this.servicePro cessInstaller1. Password = "XXXXXXXX";
this.servicePro cessInstaller1. Username = "MyUserName ";
//
// serviceInstalle r1
//
this.serviceIns taller1.Service Name = "XMLWatcher ";
//
// ProjectInstalle r
//
this.Installers .AddRange(new
System.Configur ation.Install.I nstaller[] {
this.servicePro cessInstaller1,
this.serviceIns taller1});

}
Main Intializer
private void IntializeFileSy stemWatcher()
{
//Create File System Watcher for XML files
fsWatcher=new System.IO.FileS ystemWatcher("Y :\\","*.xml");
// Add event handlers for new XML files and change of existing XML
files.
fsWatcher.Chang ed += new FileSystemEvent Handler(OnXMLFi leChanged);
fsWatcher.Creat ed += new FileSystemEvent Handler(OnXMLFi leCreated);

// Begin watching.
fsWatcher.Enabl eRaisingEvents = true;
fsWatcher1.Enab leRaisingEvents = true;
}

Nov 17 '05 #2
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.Wind owsIdentity class'
Impersonate method.

--Brian
Brian Pelton wrote:
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:
Currently I am having a problem creating a windows service that
monitors a mapped drive for events (using the FileSystemEvent Handler).
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 InitializeCompo nent()
{
this.servicePro cessInstaller1 = new
System.ServiceP rocess.ServiceP rocessInstaller ();
this.serviceIns taller1 = new
System.ServiceP rocess.ServiceI nstaller();
//
// serviceProcessI nstaller1
//
System.ServiceP rocess.ServiceC ontrollerPermis sionAccess
this.servicePro cessInstaller1. Account =
System.ServiceP rocess.ServiceA ccount.User;
this.servicePro cessInstaller1. Password = "XXXXXXXX";
this.servicePro cessInstaller1. Username = "MyUserName ";
//
// serviceInstalle r1
//
this.serviceIns taller1.Service Name = "XMLWatcher ";
//
// ProjectInstalle r
//
this.Installers .AddRange(new
System.Configur ation.Install.I nstaller[] {
this.servicePro cessInstaller1,
this.serviceIns taller1});

}
Main Intializer
private void IntializeFileSy stemWatcher()
{
//Create File System Watcher for XML files
fsWatcher=new System.IO.FileS ystemWatcher("Y :\\","*.xml");
// Add event handlers for new XML files and change of
existing XML
files.
fsWatcher.Chang ed += new
FileSystemEvent Handler(OnXMLFi leChanged);
fsWatcher.Creat ed += new
FileSystemEvent Handler(OnXMLFi leCreated);

// Begin watching.
fsWatcher.Enabl eRaisingEvents = true;
fsWatcher1.Enab leRaisingEvents = true;
}

Nov 17 '05 #3
Any idea why the mapped drive is invalid?

System Events Log:
The following information is part of the event: Service cannot be
started. System.Argument Exception: The directory name Y:\ is invalid.
at System.IO.FileS ystemWatcher..c tor(String path, String filter)
at XMLFileWatcher. XMLWatcher.Inti alizeFileSystem Watcher() in
c:\documents and settings\deskto p\service\xmlfi lewatcher.cs:li ne 147
at XMLFileWatcher. XMLWatcher.OnSt art(String[] args) in c:\documents
and settings\deskto p\service\xmlfi lewatcher.cs:li ne 610
at System.ServiceP rocess.ServiceB ase.ServiceQueu edMainCallback

Nov 17 '05 #4

"Jasonkimberson " <ja************ @gmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Any idea why the mapped drive is invalid?

System Events Log:
The following information is part of the event: Service cannot be
started. System.Argument Exception: The directory name Y:\ is invalid.
at System.IO.FileS ystemWatcher..c tor(String path, String filter)
at XMLFileWatcher. XMLWatcher.Inti alizeFileSystem Watcher() in
c:\documents and settings\deskto p\service\xmlfi lewatcher.cs:li ne 147
at XMLFileWatcher. XMLWatcher.OnSt art(String[] args) in c:\documents
and settings\deskto p\service\xmlfi lewatcher.cs:li ne 610
at System.ServiceP rocess.ServiceB ase.ServiceQueu edMainCallback


You cannot access a mapped drive that is mapped into another login session.
The drive Y: is mapped in an interactive users logon session, right?
All you can do to solve this is to map the drive in the logon session of the
service, the easiest wa to do is by executing (using
System.Diagnost ics.Process.Sta rt) a "net use..." command from your service
OnStart metod.

Willy.


Nov 17 '05 #5

I was thinking it had to do with the permissions the service was running, but if
it is a drive mapping issue, could a UNC path be used instead?

--Brian
Willy Denoyette [MVP] wrote:
"Jasonkimberson " <ja************ @gmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Any idea why the mapped drive is invalid?

System Events Log:
The following information is part of the event: Service cannot be
started. System.Argument Exception: The directory name Y:\ is invalid.
at System.IO.FileS ystemWatcher..c tor(String path, String filter)
at XMLFileWatcher. XMLWatcher.Inti alizeFileSystem Watcher() in
c:\document s and settings\deskto p\service\xmlfi lewatcher.cs:li ne 147
at XMLFileWatcher. XMLWatcher.OnSt art(String[] args) in c:\documents
and settings\deskto p\service\xmlfi lewatcher.cs:li ne 610
at System.ServiceP rocess.ServiceB ase.ServiceQueu edMainCallback

You cannot access a mapped drive that is mapped into another login session.
The drive Y: is mapped in an interactive users logon session, right?
All you can do to solve this is to map the drive in the logon session of the
service, the easiest wa to do is by executing (using
System.Diagnost ics.Process.Sta rt) a "net use..." command from your service
OnStart metod.

Willy.

Nov 17 '05 #6
Hi Willy,

Do you have any code samples of this?

thanks a lot for all the help!

Nov 17 '05 #7

"Brian Pelton" <no@email.com > wrote in message
news:et******** ******@TK2MSFTN GP14.phx.gbl...

I was thinking it had to do with the permissions the service was running,
but if it is a drive mapping issue, could a UNC path be used instead?

--Brian

Sure, UNC paths are a valid option, but this has it's own issues, services
in general don't have network access privileges (and they better don't have
them), so the service user must have access privileges to the UNC anyway, or
you need to impersonate.

Willy.

Nov 17 '05 #8

"Jasonkimberson " <ja************ @gmail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi Willy,

Do you have any code samples of this?

thanks a lot for all the help!


In OnStart() ...

// user credentials with access privs. to remote resource, don't
hardcode if you care about security ;-)
string user = "user account";
string passwd= "user pwd";
System.Diagnost ics.ProcessStar tInfo psi = new
System.Diagnost ics.ProcessStar tInfo();
psi.FileName = @"C:\WINDOWS\sy stem32\cmd.exe" ;
// The command Arguments, get servername and sharename from a config
file or hardcode...
psi.Arguments =String.Format( "/c net use \\\\servername\ \sharename
/USER:\"{0} {1}\" user, passwd);
psi.WindowStyle =System.Diagnos tics.ProcessWin dowStyle.Hidden ; //Hide
the cmd window
System.Diagnost ics.Process p = System.Diagnost ics.Process.Sta rt(psi);
//Run
p.WaitForExit() ;
if(p.ExitCode != 0)
// throw an exception to exit OnStart and signal failure to
start to the SCM
throw...
else
// Go on and start your service thread

Willy.

Nov 17 '05 #9
What is the proper syntax for this:

/c net use \\\\servername\ \sharename /USER:\"{0} {1}\" user, passwd

if i typed it into a cmd prompt? =

net use Y: \\server\folder \ /USER:domain/username password
is that correct?

Nov 17 '05 #10

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

Similar topics

3
1369
by: ThunderMusic | last post by:
Hi, I have a service that starts an application but the application always start in background (I can't see it's window) even if I set the application options to "Normal with focus". Is there a way my service can start the application and that the window can be visible? thanks ThunderMusic
29
3396
by: Ken Allen | last post by:
I have a number of services developed in C# (.Net), and they have been working fine for the most part. Recently someone reported that ipon occassion (originally rarely, but more frequently on some systems of late), there is an entry in the Event Log immediately after a boot indicating that the service failed to start after 30,000 milliseconds. Usually it starts fine when attempting manually after the boot. I instrumented the code to...
5
13412
by: SiD` | last post by:
when starting a windows service writte in vb.net, a messagebox appears: cannot start service from the command line or a debugger. A windows service must first be installed using installutil.exe and then startede with the serverexpl, windows services or the NET START command. tryed also installing with installutil: it says there is no install packs. how can I make my service work in design mode and in normal runtime mode?
0
872
by: Sukhi R | last post by:
My vb.net 2003 application running as service fails on Windows 2003 SP1 with error "The exception generated was c0000005 at address 7C8224B2 (ntdll!ExpInterlockedPopEntrySListFault)". It just crashes with no other expanations. It works fine on Win2003 and WinXP SP2. What is changes in Win2003 and what does this error mean? My service uses dotnet 1.1. I compiled it with dotnet sp1 as well, it did not make any difference.
2
1731
by: ANarula | last post by:
I am running into a strange problem. I have perl script which reads the "APPDATA" environment variable, and does some work on that directory. When I a launch this script from Command Prompt, it works perfectly fine, however when the same script is launched from a DLL hosted in a particular Service, the script fails to read the envrionment variable. Does any one has any clue, whats going wrong ? Regards,
2
2133
by: Tom | last post by:
Hi, We have a web service (developed in C# framework 1) that run for some time on Windows 2000. Recently we upgraded it to framework 2 and run successfully on Windows 2000 and XP. However, we cannot run it on our new Windows 2003 box. The service runs and we can even instantiate it but then it dies point to NULL login object. ------------------------------------------------------------------------------------- ERROR(7/27/2006 2:55 PM):
4
21714
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a webserver to see if service A needs to be updated. What service B does if it sees their is an update for service A is to download a new copy of the service A executable, stop service A, replace the executable with the new copy, and start service B...
1
1613
by: =?Utf-8?B?c3VyZmtlaXRo?= | last post by:
A machine running XP Home fails to start the cryptographic service. When attempting to start from the services menu it responds with error 2: the file specified cannot be found. I am unable to identify which file it is referring to however I have run through various procedures from articles found in the discussion forums,a on the ms web site and including www.updatexp.com/cryptographic-services.html. Due to cryptographic services...
1
5653
by: aj | last post by:
A few service stop/start/restart questions on SQL Server 2005 SP2, which I'll call SQLS. It looks as if there are *potentially* 6 ways to start/stop SQLS Services like the engine itself, integration services, reporting service, Agent.. -SQLS Configuration Manager -SQLS Surface Area Configuration (for Services and Connections) -Mgmt Studio Local (on server)
0
8172
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.