CHANDRA
CHANDRA

Reputation: 4938

Issue to move file from one folder to another using window service, running as NetworkService

I want to move .txt file from one folder to another when window service is starting up.

protected override void OnStart()
    {
        string sourceFile = @"d:\Source\file.txt";
        string destinationFile = @"D:\Destination\file.txt";
        File.Move(sourceFile, destinationFile);
    }

this code is working well when the serviceProcessInstaller1 Accunt type is LocalSystem. If i change the serviceProcessInstaller1 Accunt type is NetworkService, I will get an error access to the path is denied. Help me to solve this issue ?

Upvotes: 1

Views: 2236

Answers (1)

superarce
superarce

Reputation: 403

Your problem here is the user permissions in the machine. Try changing the permissions to the file and the folder and set them less restricted. I'm sure that if you set all permissions to all users, your service will work. But it's risky too.

In this page, "File Access" section, you can read how to configure this permissions.

Upvotes: 1

Related Questions