Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Hi All,

	I used DeleteFile API as follow :

	DeleteFile("\\\\MachineName\\ShareName\\FileName.txt");

	where 
	\\\\MachineName\\ShareName\\FileName.txt  full qualified path of remote machine

	When i create simple Win32 or MFC App and Runs, then file get delete successfully.

	but similar code i added in Win32 Service then its fails.

	can anyone tell me the reason behind that.

	My service running in System account which has full priveledges, then why DeleteFile API fails in
	system account for network file.

	i got GetLastError() == 5 (Access Denied)


What I have tried:

Under Service
1>
DeleteFile("Del \\\\MachineName\\ShareName\\FileName.txt");

2>
System("Del \\\\MachineName\\ShareName\\FileName.txt");

3>
WNetAddConnection2 for IPC$ (Success)
before 1 and 2
still not success
Posted
Updated 3-Aug-16 2:48am
Comments
Philippe Mori 3-Aug-16 9:59am    
Improve your formatting... You should use code block for actual code and regular text for normal text.

1 solution

The System account under which your Service runs, does not have Access rights to e.g. Network Shares.

Find some more explanations here:file permissions - Windows Service can't access network share - Stack Overflow[^]
 
Share this answer
 

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