Click here to Skip to main content
16,022,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have built a C program in Visual Studio 2022. This program shall list files from a fileshare (network disc) and file by file process some work and after that move the processed file to another directory on the fileshare.

When I try to run the program in debug mode in Visual Studio 2022 everything works so the functionality seems to be in place.

My customer needs to install this as a Windows service, so I have built the program as a Windows Service also. But when I try to execute the program as a service the program cannot found any files.

Maybe it's something with permission, I don't know.
It is installed as a Local System.

Are there someone that can help me with this?

Mr Big Spender

What I have tried:

I have tried to configure the Windows service in several ways and debugged my code with printing logs.
Posted
Comments
Richard Deeming 23-Sep-24 6:09am    
"Local system" uses the computer's account for network requests. Unless the share has specifically been configured to allow the computer account to access it, you'll most likely be hitting a permissions issue.

Try configuring the service to run as a dedicated network user.

1 solution

Local System does not have access to network shares. Like Richard said, you have to grant the machine account permissions on the share and NTFS permissions to the underlying folder.

You would never do this in a real production environment though. You should be creating a dedicated user account just for the purpose of running this service. Make sure the password on the account does not expire and setup the service to use this account. Give the account appropriate permissions to share and filesystem as appropriate.

This way, you're not giving your service admin permissions to the entire machine the service is running on and creating a possible security risk.
 
Share this answer
 
Comments
Håkan Axheim 2022 26-Sep-24 1:04am    
HI,

But if open up Windows explorer and try to list files on shared folder whith this path:
\\<ip number="">\<share>$\Directory1\Directory2\Directory3\Directory4\Directory5 all files will be listed
If I try list files with this command:
\\<ip number="">\<share>$\Directory1\Directory2\Directory3\Directory4\Directory5\*.* no files will be listed.

The I get Network error with code 0x80004005

Regards
Mr Big Spender
Dave Kreskowiak 26-Sep-24 9:40am    
Yeah, so?

0x80004005 is ERROR_ACCESS_DENIED. That's why I said setup a user account specifically for the service AND setup the share permissions AND setup the NTFS file system permissions under that share.

Oh, and the $ shares are admin shares and shouldn't be used in production applications at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900