File access from Windows Service

  • Thread starter Thread starter Niklas Elelid
  • Start date Start date
N

Niklas Elelid

Hi!

I´m writing a Windows Service in VB.NET that should open and write to
a file on a remote machine. The remote machine is not on the same
domain as the machine running the service.

If I run my application as a normal Windows application it can use the
mapped drive (k:\) that I have set up, but when running the service I
only get a "Could not find part of the path k:\dns\" error.

I guess this has to do with the fact that the service is running under
a different user account (LOCAL SYSTEM), but I´ve also tried to set up
the service to logon using the logged on desktop account
(administrator) that has got the mapped drive.

How can I possibly solve this? I have tried with impersonation but I
can´t get it to logon properly to any other machine but my local
machine.

Many thanks in advance!

Niklas Elelid
Stockholm, Sweden
 
Hi Niklas,

You have written it with VB.net but most of us are not installing webserver
very fast after each other and because of all security patches and other
security work Microsoft does now, those things you mention are changing
faster than everything else.

I would put this question too in the asp.net and in the IIS groups.

I would not say you don't get your answer here, but the change is very low.

Sorry I could not help you better,

Cor
 
You need to be running under an account that has access to both machines.
Assuming that there is a trust between the domains (there must be if this is
to work), you need a domain account created. You need to grant that account
the "logon as a service" right on the machine on which the service is to
run. Setup the service to run under those credentials.

On the target machines, that domain account must have rights to write to the
file.

Jerry
 
You don't actually have to use mapped drives at all. Have you tried using
the unc path of the server/computer you're trying to write the file to?

ie. \\computer1\c$\textfile.txt if you have the computer name, if not then
use an ip address if possible such as \\24.72.56.122\c$\textfile.txt

If you're running the service as an account that has access to both domains
(as Jerry wrote in this thread) then you should be alright.
 
Many thanks guys!

I took both your advice and switched to UNC, and set the "Logon as
service" parameter, presto!! It works!

Thanks
Niklas
 
Back
Top