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;
} 14 7163
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 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; }
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: 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 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; }
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
"Jasonkimberson" <ja************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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.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
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.Diagnostics.Process.Start) a "net use..." command from your service
OnStart metod.
Willy.
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.googlegr oups.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.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
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.Diagnostics.Process.Start) a "net use..." command from your service OnStart metod.
Willy.
Hi Willy,
Do you have any code samples of this?
thanks a lot for all the help!
"Brian Pelton" <no@email.com> wrote in message
news:et**************@TK2MSFTNGP14.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.
"Jasonkimberson" <ja************@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.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.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\WINDOWS\system32\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.Diagnostics.ProcessWindowStyle.Hidden; //Hide
the cmd window
System.Diagnostics.Process p = System.Diagnostics.Process.Start(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.
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?
psi.Arguments =String.Format( "/c net use \\\\servername\\sharename
/USER:\\{0} {1}\\", user, passwd);
psi.Arguments =String.Format( "/c net use \\\\servername\\sharename
/USER:\\{0} {1}\\", user, passwd);
I was testing out the map drive before i added it to code
NET USE U: \\master\testshare /User:domain\usernamei passwd
/PERSISTENT:YES
but i get a error
"System error 67 has occurred.
The network name cannot be found."
I am on Windows 2003, and i have already gone to MSDN = http://support.microsoft.com/?kbid=843156
as for their solution 1: my network driver seems to be working fine.
as for their solution 2: i dont have a IP Network Address translator in
the Non-Plug and play drivers
that didnt work for me
but what did work was
using IWshRuntimeLibrary;
public static void createmappeddrive(string driveletter, string
username, string pass)
{
bool blnUpdateProfile = false;
bool blnForce = true;
object objblnForce = (object)blnForce;
object objblnUpdateProfile = (object)blnUpdateProfile;
object objstrUserName;
object objstrPassword;
string strMapDriveLetter = driveletter + ":";
WshNetworkClass wshNET = new WshNetworkClass();
//"cbcg\\rwma"
objstrUserName = (object)username;
objstrPassword = (object)pass;
wshNET.MapNetworkDrive(strMapDriveLetter, @"\\networklocation\", ref
objblnUpdateProfile,ref objstrUserName, ref objstrPassword);
}
public static void removemapdrive(string driveletter)
{
bool blnUpdateProfile = false;
bool blnForce = true;
WshNetworkClass wshNET = new WshNetworkClass();
object objblnForce = (object)blnForce;
object objblnUpdateProfile = (object)blnUpdateProfile;
string strMapDriveLetter = driveletter + ":";
wshNET.RemoveNetworkDrive(strMapDriveLetter,ref objblnForce,ref
objblnUpdateProfile);
}
i wrote those to open and close a mapped drive before and after a
service is started and stopped
that didnt work for me
but what did work was
using IWshRuntimeLibrary;
public static void createmappeddrive(string driveletter, string
username, string pass)
{
bool blnUpdateProfile = false;
bool blnForce = true;
object objblnForce = (object)blnForce;
object objblnUpdateProfile = (object)blnUpdateProfile;
object objstrUserName;
object objstrPassword;
string strMapDriveLetter = driveletter + ":";
WshNetworkClass wshNET = new WshNetworkClass();
objstrUserName = (object)username;
objstrPassword = (object)pass;
wshNET.MapNetworkDrive(strMapDriveLetter, @"\\networklocation\", ref
objblnUpdateProfile,ref objstrUserName, ref objstrPassword);
}
public static void removemapdrive(string driveletter)
{
bool blnUpdateProfile = false;
bool blnForce = true;
WshNetworkClass wshNET = new WshNetworkClass();
object objblnForce = (object)blnForce;
object objblnUpdateProfile = (object)blnUpdateProfile;
string strMapDriveLetter = driveletter + ":";
wshNET.RemoveNetworkDrive(strMapDriveLetter,ref objblnForce,ref
objblnUpdateProfile);
}
i wrote those to open and close a mapped drive before and after a
service is started and stopped This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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 ...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |