Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi,

My application is a service, and using that i am creating a folder and a file in it, on C: (whr operating system is installed)
However, once that is created, i am unable to delete it (the file within the folder) manually also. windows gives error - "error deleting file/folder. Make sure the file is not write protected or in use."

When i create the fodler on any other drive, say d:, i can delete the folder.

When i run the same application, not as a service, I am able to delete the file and the folder, irrespective on whether it is created on C: or D:.


Can anypne pls let me know the possible cause of the same? Probably the rights given to the user on C: while service is creating the folder are restricted. Is there any solution for this?

Thanks in advance,
Manasi.
Posted
Comments
Sergey Alexandrovich Kryukov 10-Feb-11 12:49pm    
Did you take care of security permissions for your service at all? Did you try deleting the file as a non-privileged user?
--SA

1 solution

When you're running your service, you're not logged as the same user as that of your account. Run your service, then look at its properties:

%SystemRoot%\system32\services.msc /s


It will show Services applet; see "Log on as"; the typical users are "Local System", "Network Service", etc. Your files should be accessible by that user you used for your service. The other way is to change installation of the service to some authenticated user registered on your system.

—SA
 
Share this answer
 
v2
Comments
#realJSOP 10-Feb-11 13:01pm    
Propose as answer
Manasi D 11-Feb-11 6:42am    
hi..i think i will check the installation of the service..thanks!
Sergey Alexandrovich Kryukov 11-Feb-11 14:30pm    
You're welcome, thanks for accepting my answer.
--SA
Sergey Alexandrovich Kryukov 11-Feb-11 14:21pm    
Who is so clever to vote "1"? A revenge? Ha-ha...
--SA
Manasi D 14-Feb-11 11:30am    
hi, to solve the problem, i am trying to provide username and password for CreateService() API. But its not getting accepted. Even if i try to change the logon information manually, it says "Cannot open the service for writing on local computer. Error 5: Access denied". What is it that i am supposed to do,if i want the service to run as different user?

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