Path references in a .NET Windows Service Application

  • Thread starter Thread starter Zachariah
  • Start date Start date
Z

Zachariah

I created a Windows Service and part of its functionality
is to move a PDF file from a location on the service's
local drive stInPath (C:\PDF\) to a location on another
server stOutPath (\\123.123.123.123\C\PDF\) with this line
of code:

fs.MoveFile(stInPath, stOutPath)

For testing I've been using the same code in a windows
Application form. When I run the Application Form the
file move is successfull. When I run the code in my
service however, it doesn't do the move. If I have my
service move locally it works. I've tried mapping the IP
address to a drive letter and referencing that but it
doesn't move that way either. Is there some trick I'm
missing about path references in Windows Services?
 
Zachariah,

Your problem is with the Network credentials of the Service. When you run
the application form, the application uses the credentials of the logged on
user (you) and therefore can connect to the remote resource.

when you run the code as a service, the service runs under the security
context of the local system account. The local system account cannot copy
files to a remote location since the destination machine has no knowledge of
the local system account. This would explain why you can move locally when
running as a service but not remotely. To get around this, open the services
manager and specify a logon account for the service. This should resolve
your issue. Let me know how it works out.

Eric
 
Back
Top