Access Windows Share in a network service account

I have two computers running Windows Server 2003. One computer has shared folders on the network, and the other has a Windows service (written in C # running under the Network Service account) that must access these shared folders.

The following code works fine as the user who logged in, but throws an exception when executed in the Network Service account.

File.WriteAllText(@"C:\temp\temp.txt", File.ReadAllLines(@"\\NetworkServer\Test\test.txt")[0]); 

Logon failure: unknown user name or bad password exception message. How to make this code work under the Network Service account? Is this a setting in Windows Server 2003 or do I need to add code for this to work?

+4
source share
2 answers

In a network share, you will need to add permissions for the Network Service account on the server on which the service is running. Although this will work, @nicholas points out that it may provide too broad a group of users to access this share.

Another option and, in my opinion, the best option is to create a domain account, and then grant permission to read and write the account on the shared resource. Then you configure the service to run as a domain account with the appropriate permissions.

+3
source
Answer to

@Nate is either incorrect or unclear as far as I can tell. He does not explain how Network Service authenticates with the network.

Network Service account has very limited privileges on the local system; it represents the credentials of computers on the network. Therefore, if you need to access a network resource (for example, a network resource) in the Network Service account, you need to provide access to the account of the computer on which the service is running.

Providing a local Network Service account with access to a network resource will not work at all, you will continue to receive authorization / authorization errors.

See the MDSN link "NetworkService Account" .

0
source

All Articles