开发者

Block access to a file

开发者 https://www.devze.com 2023-02-16 21:53 出处:网络
i want to make a program which block any file(like autorun.inf),so that no other program can read from it(just like a way,antivirus do) with c++ in windows.

i want to make a program which block any file(like autorun.inf),so that no other program can read from it(just like a way,antivirus do) with c++ in windows. please help me. thanks开发者_运维百科.


You can open a file with a dwShareMode of 0, which will

Prevents other processes from opening a file or device if they request delete, read, or write access.

So once your process opens the file, no other process will be able to open it, delete it, etc.

MSDN Reference


either set the NTFS ACLs on the file

or

use CreateFile() to open the file with dwShareMode=0 http://msdn.microsoft.com/en-us/library/aa363858(v=vs.85).aspx


You could encrypt the file. If it's unreadable it's unusable!

A simple xor will do.

0

精彩评论

暂无评论...
验证码 换一张
取 消