开发者

How to prevent a file being copied or cut in windows file system?

I want that an exe file can't be copied or cut from the Windows file system to paste somewhere.

The exe is made in C#. which must have to be in only one PC.

I have worked with FileSystemWatcher, NSIS, Clipboard. but for all I need to detect whether that file is being copied.

I also have seen 'Prevent'(http www free-download-blog.com disable-cut-paste-copy-delete-rename-functions-using-prevent ), but I need to prevent only that particular exe开发者_开发问答 from being copied or cut.

Any pointer or idea will help.


If you need the exe to be executable, you need to permit loading it into memory. As soon as you do, anyone can read it to memory using ReadFile and then write to an arbitrary location using WriteFile. No shell-detectable copying involved.

A good reading: Raymond's post and its comments on preventing copying.


As others have suggested you won't be able to disable the copy/cut behaviour so easily.
An alternative would be to disable the execution of the copied versions.
In your executable you could check many things like :

  • The path of the present executable is explicitly your_path
  • The name of the machine and user is the one you authorise

You could even prevent the file of being executed more than once using Windows register entries (if already 1 don't launch). It won't be perfect since any experimented user could tweak that out, assuming they are seeking for that. But depending on your users profile it might be sufficient.


Well, this is a hard problem. Even if you get explorer.exe to disable cut&paste, what prevents a user from using the command window? Or writing their own exe to do it? Booting up in linux and reading it?

Still, you have a few options (there will be more, most likely) which you could try:

  • Use the right permissions: Set the permissions such that the users who you don't want to cut&paste cannot read the file.

  • Write a device driver which can hook onto the filesystem calls and do that for you.

  • Encrypt the file.

And some hacky options like:

  • Use the APPINIT_DLLS regkey to put your own dll to be loaded into each process ( I am not sure if this will work with console process though). Then on your dll load, do IAT hooking to replace the kernel32.dll file calls.

  • Replace kernel32.dll with your own version. Might have to do some messing around with the PE format etc.

There are no guarantees though. If for instance, you expect them to be able to execute it, but not copy it, you are probably stuck.


Any local admin will be able to undo anything you do to prevent copying. I can pretty much guarantee the program on that page you mention relies on a service or background process to prevent copy-and-paste, and therefore is easily circumventable. If your users are in a closed environment where none of them are admins and they have very limited rights to their PCs, then you have a chance.


if you could completly block explorer from copying or moving files, then all u need is a 3rd party software for copying files (but make sure it can filter file extensions) for example Copy Handler


Set up an ENVIRONMENT variable in your machine

In your code add a check if (ENVIRONMENT Variable=='Same as defined') //Execute code else //Suspend execution

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜