Windows Service File Access problem

  • Thread starter Thread starter marc.gibian
  • Start date Start date
M

marc.gibian

I am writing a small Windows Service in C#. It is structured as two C#
programs, one, let's call it myAction, that runs as a command line
program and a second, let's call it myWrapper, that is the actual
windows service, which starts the first program as a child process (and
then waits for the child process to terminate, restarting it should
that ever happen).

When run on its own from a shell window, myAction opens and reads its
input files without any problem.

When run from within myWrapper, myAction appears not to have sufficient
permission to access its input files.

A little additional research has shown that if the input files reside
on the local disk, myAction always works properly, standalone or from
myWrapper. If the files reside on a network drive, only the myWrapper
invocation fails.

The service is instaled with the Visual Studio .NET 2003 generated
setup complete with the necessary ProjectInstaller, containing a
ServiceInstaller and ServiceProcessInstaller. I am specifying my
network login for the service during its installation, and
Environment.UserName seems to indicate the service is indeed running
under my network account.

This application really needs to be able to operate on files residing
both locally and on network drives, so I need to fully understand what
is going on here. I remember there is some magic incantation that needs
recitation for this, but I can't remember the words.
Thanks for your help...
 
Are you accessing the files on the network servers using a UNC path?

Willy.
 
Hi Willy,

The network test path is "j:\testdir\filename". My local test path is
"c:\testdir\filename" and that one works with no problem.

-Marc
 
That's your problem, J: is a mapped drive, but the session to wich it is
mapped is not the "service logon session" but the "interactive logon
session" and in Sessions cannot be shared in Windows even if both refer to
the same user account.
So you have to create a new session from within your service, or
(preferably) you have to use a UNC path.

Willy.
 
Okay, I understand the problem... now I need help with the fix. I am
installing my service from a setup generated from Visual Studio .NET
2003. I have the user entering the filepath for the input file for my
service. I am not sure how I take that user input (from an optional
text box dialog) and convert it into the UNC path (which I should be
able to do since the install is running in the user's session... it
also gives me the chance to validate that the supplied filepath
resolves to an actual file) which I then store in a registry key value.
Right now the install is just unconditionally creating the key value
with the content the user supplies, and no validation. I can't find any
documentation on how I do this, though I presume I need a custom
action?

Thanks very much for your help,
Marc
 
Back
Top