Creating my own extension
I was wondering...
I have a program that stores text files in the "App.Path".
The extension I have given these files are ".khj".
Double clicking on it, windows asks you what do you want to open it with. That is good, because I don't want my users opening these setting files. However, if they say to open the file with notepad, all the data is displayed, perfectly...
So my question is, how do I make a new extension, that can't just be opened by notepad or word. So only MY program can read it?
I'm guessing that it might have something to do with encryption?
Or am I wrong?
Thanks
Re: Creating my own extension
You're right that it's about encrytion but you can't stop other programs from opening a file. You'll need to use encryption to prtect the data.
Re: Creating my own extension
So the best way to go about this would to be encrypt the data so that when opened in notepad it comes out scrambled? There's no other way to do it?
Re: Creating my own extension
You can't keep another program from opening the file. Unless you open the file in Lock mode from your program, but your program would need to always be open. Ex:
vb Code:
Private Sub Form_Load()
Open "C:\test.txt" For Input Lock Read As #1
Then trying to open it with notepad, you would get the error:
"The process cannot access the file because it is being used by another process."
But if someone closes your program then so much for that...
Re: Creating my own extension
Yeah, good idea, but nah.
So my next question would be, encryption, whats the best way to go about that?
Re: Creating my own extension
Re: Creating my own extension
If you don't want to go throught the 'custom' encyption route, there is another simple solution. You could wrap your text files in a password-protected zip file. This can be done programatically using the command-line verison of of 7-Zip (freeware), and the file can still have your .khj extension (it doesn't have to be *.zip).
Re: Creating my own extension
Quote:
Originally Posted by feneck
Double clicking on it, windows asks you what do you want to open it with. That is good, because I don't want my users opening these setting files.
If you want to set how the files look in explorer, like assigning them an icon and setting the Details View decription to something other than "khj file", as well as define the action that happens when they're double-clicked, see this thread for details.