Home All Groups Group Topic Archive Search About

File.Copy to UNC path location with service

Author
6 Apr 2005 11:07 PM
Chris Williams (Sirana)
I've got a two line code snippet that copies a file from a local directory to
a server share that's accessed via a UNC path.

When I run this code snippet in a Windows forms app, while logged in as
myself, it runs fine and the file is copied.

When I run this code snippet in a Windows service, even when the service is
running under my account, the code snippet fails with a
system.unauthorizedaccess exception and the file copy fails.

I've verified in the service code that the service is running under my
account right at the point of failure. The account happens to be a domain
administrator account.  Also, the share on the remote server has Full Access
granted to this account.

Any ideas would be appreciated.
--------------------
Chris Williams
Sirana Software
www.sirana.com

Author
7 Apr 2005 10:17 PM
richlm
This sounds like a delegation issue. Basically you have to give your domain
account enough privilege to allow one server to do stuff on another server.

With a domain at Windows 2000 functional level it's either on or off per
user account:
  1.. Within the Users folder of Active Directory Users and Computers,
right-click the user account that is used to run the server process that
will impersonate the client, and then click Properties.
  2.. Click the Account tab.
  3.. Within the Account options list, scroll down and click Account is
trusted for delegation.
If your domain controller is Windows 2003 and you raised the functional
level you can configure things to a much finer level of detail, for example
"services running as account A on Server1 can access file shares on
Server2". As above but on properties there's a new delegation tab. Here's a
link if you need the finer details:
http://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologies/security/constdel.mspx

Hope this helps.