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

Can anyone tell me that, How to make a file as write Protected Programmatically using WIN32.
I have created the file like this:

C++
HANDLE hFile = CreateFile("E:\\FileName.txt", GENERIC_READ,FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_ALWAYS, FILE_ATTRIBUTE_READONLY, 0);

After creating a file, When i try to copy that file to other location, It should not copy.. Please sugest me..!

Thanks in Advance.



Is there any way to make it Programmatically with out using User Account Control Features.. ??
Posted
Updated 11-Mar-12 23:15pm
v4
Comments
perilbrain 12-Mar-12 4:45am    
I dont think you can stop a file from being copied without putting a watcher on it...
Write Protected implies the file is readonly and you cant change it, it has nothing to take from whether it is being copied or not....
Nelek 12-Mar-12 5:15am    
Edit: Answer from OP added here

You have made your file read only but that means that anyone can read (and copy) it. If you want it to be totally protected then you must use the User Account Control features to secure it.
 
Share this answer
 
Comments
Guru_C++ 12-Mar-12 5:00am    
Is there any way to make it Programmatically with out using User Account Control Features..
Chandrasekharan P 12-Mar-12 5:08am    
Request you to delete your question which you have posted as Solution 2
Nelek 12-Mar-12 5:14am    
As long as the file is opened, if you use "CFile::shareExclusive" then you can get a bit more protection than you have. But... once the file is closed another time, there will still be possible to copy it, move it or whatever.
Richard MacCutchan 12-Mar-12 5:26am    
Not that I am aware of. Basic file attributes do not provide any useful file protection.
Guru_C++ 12-Mar-12 5:37am    
Yes.. Ur right.. In basic file attributes we don't have such options.
So I came to understand from your previous question that you want your file to restrict it from being copied.
If I talk like a hacker I will say there is no way to do it :(
Explaination:-
1. ACL Protection work with windows, however I can run Linux and copy it out easily.
2.Any process running with high privilege with that of File itself,is able to copy that file.

Workaround for (2.):-
You can write a service for locking that file and stop it from being copied.
Like the way antiviruses do ..
You can research with these links and can check out if there is anyother way to do it... http://stackoverflow.com/questions/853805/locking-files-using-c-on-windows[^]
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365203(v=vs.85).aspx[^]
 
Share this answer
 
Comments
Mohibur Rashid 14-Mar-12 3:16am    
I agree with your number two point. but not with number one
About security issue I disagree with you.

First thing on about security is physical security. if you user can remove the hard-disk form the system and run under linux or if simply user put a bootable CD and boot operating system then there is no security at all.

If you have physical access to any linux system you dont need to log in to change the password of the system
Computers work by copying data from a memory location into another, and another and another.
If you have data you don't want to be copied ... don't store them on computers.
(and let people use copy machines ...)

If your problem is to protected the DATA (not the file ...) from being somehow stolen then encrypt the data in a way you only can decrypt them. At that point, copying the file itself will be clueless.
 
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