Windows Service, I/O problems?!

  • Thread starter Thread starter Anders
  • Start date Start date
A

Anders

Hi all,

I have an console app that looks in one folder (e.g.
c:\temp) and copies all files to a couple of other
folders, one local folder (e.g. d:\temp) and one mounted
folder (e.g. x:\).
All this works fine, but....when I run this application
as a Windows Service the System.IO.File.Copy
(file,newFile,true) throws an
System.IO.DirectoryNotFoundException saying: Could not
find part of the path "x:\newFile.ext"

I have tried running the service as "Local System" and as
User (logged on as me) so the process will run as the
same as the console app.....but there is no difference =(

Any ideas?!

Cheers

//Anders =)
 
To access the network from within a Window Service, you definitively cannot
start the Service with System account. This will not work.

Now, If you start it using your own account name, are you positive that the
x: drive is mounted and seen as such by your service?

José
 
Anders, could you try using a UNC path instead of a mapped drive? ie.
\\servername\fileshare\
 
Greg:
Thanx for your reply,
I have tried using the UNC path instead and it works. But I do not know
if this is because I already has the drive mappped. I have tried
installing my service on another machine, and then it doesn't work with
the UNC path either.

José:
Thanx for your reply,
I do not really understand what you mean with your question.
"Now, If you start it using your own account name, are you positive that
the
x: drive is mounted and seen as such by your service?"

//Anders =)
 
Greg:
thanx for your reply,
I have tried using the UNC path instead, and that works
fine. But I don't know if this is because I already have
the drive mapped...

José:
thanx for your reply,
Yes, I'm sure the drive is mounted....but what do you
mean with "...and seen as such by your service?"

//Anders =)
 
If was wondering if the x:\ drive is seen as mounted by your service.
To get a list of drive currently reachable by your application you can
execute Environment.GetLogicalDrives()
(refer to online help for a sample).
You could run it from within your service just to check it is available.

José
Greg:
thanx for your reply,
I have tried using the UNC path instead, and that works
fine. But I don't know if this is because I already have
the drive mapped...

José:
thanx for your reply,
Yes, I'm sure the drive is mounted....but what do you
mean with "...and seen as such by your service?"

//Anders =)
 
Frankly, I'm not sure I'm correct. However, I believe that mounted drives
are allocated per user session (I believe that if you mount a drive on one
user account, it will not be seen on another user account)

To test this, you could run "cmd.exe" using different users (assuming you
have W2k or XP, press Shift and right mouse click on cmd.exe and choose
'runas').
In one dos shell, mount some drives and check if they are seen by the other
user.


José
"Anders" <[email protected]> a écrit dans le message de
Hi José,

I tried to list all logical drives from my service - and
you were right, none of my mounted drives were listed...
(I got quite a few drives mounted). Do you know why?

I tried running the service with both Local System and
User (with my account) - no difference...

//Anders =)
 
You need to impersonate when accessing Network resources from Windows services running with local account credentials.

Willy.
 
Back
Top