views:

81

answers:

2

I have a file that I need to "protect" so that it cannot be copied! I am using Python on Windows XP.

I think it may just be changing file permissions??

+2  A: 

You can prevent the file being copied only by removing read permission from the user that shouldn't be able to copy the file. You can use os.chmod for this, or see this page explaining to set permissions with the full Windows security model.

calmh
Would my software still be able to read from it? How do I do this in Python?
Zachary Brown
If your software runs as a special user, you can make sure only that user has read access to the file. I updated the answer with a link to a page that describes how to set advanced permissions.
calmh
A: 

Is this a temporary or a permanent file? If it's temporary, take a look at the tempfile module, especially tempfile.mkstemp().

Tim Pietzcker
No, it is a permanent file. It is a file that I will place on the drive to tell my software that it is registered and a valid copy. That is why I need to make sure it cannot be copied.
Zachary Brown
OK, so your software licence is on a per-machine basis, not a per-user-basis, then? Why not connect the licence to a physical feature of the machine then, like http://stackoverflow.com/questions/227222/how-can-you-extract-hardware-id-using-python - but also look at http://stackoverflow.com/questions/1473143/methods-to-stop-software-piracy.
Tim Pietzcker