Archive: Writing Copy Protection Codes to Registry in Windows??


Writing Copy Protection Codes to Registry in Windows??
I have an immediate need to figure out how to get NSIS to make a registry entry of a serial number, so I can then call it up and check it via a Visual Basic user app.(assuming I go with a mathemically based key generator). The software would then install, but wouldn't start if the serial number entered didn't conform to the the proper key generator algorithm. I might use a user ID as well, and may key the algorithm off of it, which would mean I'd want the registry to contain both, with the user ID as a means of providing tracing back to the user.

I can't just go with one or the other, because I don't plan to constantly recompile Visual Basic source code to accomodate a new user ID. If I put the ID or serial number in an external file and read it into VB to verify versus the registry entry, the file can be transferred by a simple directory copy to any other computer, which means that the VB software check at start-up has to be based on a key.

The installation file start could be based on either or both, as long as I can get the user to enter a key that I can either confirm matehmatically to conform to the "secret" algorithm or get the user to enter an ID that is then read from a text file that is somehow bundled into the set up. Any suggestions on this, or on how to make these registry entries (and provide for deinstallation of these registry entries)?

Thank you.


I don't understand your question. What exactly are you trying to figure out? How to write a registry key? That's done using WriteRegStr, but you probably know that already...


No, I don't know that already... I started using this software at more than the "so this is what the interface looks like" level yesterday. I really need some help identifying how to specifically implement the code so that I write to a registry entry that won't make Window's crash, and is readable by Visual Basic 5.0 in straightforward fashion (hopefully into a normal string variable).

I'd also like any suggestions with regard to copy protection and how to pull it off. I've never attempted it before, and I clearly don't want to come up with something so lame that it can't work in practice, or is too much for me to manage. I need to be realistic in my copy protection concept, including how I'm going to pull it off on a server with nothing but Publisher 98 to produce the web page that sells the software. I don't expect massive sales, and was thinking I would begin with manual shipment with a serial number and key sent via e-mail, but would need to be able to switch to internet automation if something odd happens and the software sales reach a level that makes this impractical, forcing automation.

Thank you.


so basically, all you want is to store program registration information in the registry?

well, i guess you know how to read/write the registry in your program itself, correct?

so you should know something about the registry and how it works.

if not, i suggest you google for a tutorial on the registry first, before you begin messing your users' systems.

after that, or if you already know those things, you should read the documentation of NSIS, especially the parts about "WriteRegStr" and "ReadRegStr". (search for those keywords in the index)


I came, I saw, I Googled, and found little that was useful...
I came, I saw, I Googled, and found little that was useful...

Google's search produced dead end links and fluff with regard to the Windows registry, as well as some, "well, you already know everything there is to know about the registry" articles.

I could use any pointers that you may have, including those to good tutorials for beginners that are actually valid and active links.

You're right. I don't want to mess around with someone's registry in a destructive or harmful manner.

Thank you.


Sorry, allow me to ask, does this make any sence to you?

ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe"  "path"
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myapp.exe" "" "$INSTDIR\myapp.exe"
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myapp.exe" "path" "$INSTDIR"

This is a plain explanation on how NSIS deals with registry.

Check this out
HM NIS Edit creates a good starting format for installers. You can get the basics out of the way like copying files.

http://hmne.sourceforge.net/

If you don't know much about the registry then I suggest making a backup of the registry before even starting to mess with it. Here's how you make a backup:

1. Click the Start Menu
2. Click Run...
3. Type "regedit" without quotes (I recommend using regedit rather than regedt32 because regedit has a better search capability).
4. Right click on My Computer (that's in regedit, see screenshot)
5. Click Export
6. Name it registry_back.reg and save it to a USB Flash drive or some sort of drive you can access if the computer won't start.

Messing with the registry is very dangers. You can, and probably will, screw something up if you don't know what you're doing causing the system to no longer boot.
SAM


Re: Check this out

Originally posted by sag47
...
6. Name it registry_back.reg and save it to a USB Flash drive or some sort of drive you can access if the computer won't start.
...
Apologies... am I missing something here?
Could you explain me how am I supposed to access the removable drive if the computer won't start?

Small registry tutorial Part 1 of 2
Use regedit to browse the registry and figure out how it works but don't change anything unless you know what it does.

Here's a quick explanation about one particular thing...file associations.

Open HKEY_CLASSES_ROOT

You will see other directories such as *, .htm, .html, .anyfile

These are all file extensions if it begins with a ".". "*" means this is for all files. Go to the directory .txt (refer to screenshot1.png on attached files)

Once you click on HKEY_CLASSES_ROOT\.txt, look at the fields to the right. Every registry folder entry has a (Default) section. If you look to the right of it you will see that it refers to txtfile. This means for all files that end with .txt refer to the section HKEY_CLASSES_ROOT\txtfile.

Now double click on (Default) but don't change any values. You see a dialog come up where you can edit txtfile. So now lets go over another fundamental value of the registry. HKEY_CLASSES_ROOT is the root key. .txt is a subkey (which refers you to the subkey txtfile). (Default) is known as an enty name. And txtfile (under the (Default) entry) is known as a value, entry value, or new_value_string.\

So if you were using ReadRegStr to read what the value where txtfile under .txt is then the command would look like this...

ReadRegStr $0 HKCR ".txt" ""

$0 means to save whatever is read into $0. It's the same thing as saying $0=txtfile.

Read the next post for Part 2 of this tutorial (2 parts for 2 pictures)

There is a category at wiki named tutorials
I'd suggest publish these tutorials up there, so they would be easy accessible to everyone!


Small registry tutorial Part 2 of 2
Refer to screenshot2.png (attached) for a visual of what I am saying.

Now browse to the HKEY_CLASSES_ROOT\txtfile subkey. In the (Default) entry name under the txtfile subkey you see the description of what a text file is, "Text Document". This tells users what kind of file it is. If you make a new text file and hover your mouse over it then it will say "Description: Text Document". Now look at the "DefaultIcon" subkey and you see the default entry name has a value for where to grab the icon. This is how an associated file gets it's own icon.

Now open the "shell" subkey. Shell is basically all of the right click options of any file.

Now click on the "open" subkey (located within the shell subkey) and you will see the default entry is empty or (value not set). Well when no value is set the Windows automatically gives it the value "Open" by default. Right click on a text file and look that the top bold entry to open it, it says open. Now give that entry a value (you are changing the HKEY_CLASSES_ROOT\txtfile\shell\open subkey's default value). Give it the entry "Open textfile" without quotes. Now right click on a text file. Rather than saying Open it now says Open textfile.

The subkey command, located under the txtfile\shell\open subkeys, is the action Windows takes when you click on that particular entry of the right click options on the file.

That was a small registry in a nutshell. I don't want to write a book and I have to go. But I hope I was of some help.

Merry Christmas,
Happy Holidays!
SAM


ok i'll copy the tutorials into there later, i have to go for right now.
bye!
SAM


Thanks, Noel, Feliz Navidad and Kala Christougena!
Ah, knowledge, the gift that keeps on giving!


Okay,

I'll "enhance" the tutorial by "playing" the part of the clueless newbie seeking to reply to the local mentors to try to determine if he's learned anything.

Just a note to SAG47. The registry tree structure on my Windows 98SE system with regard to folders is as follows for ".txt" under HKCR:

HKCR -|
|-txt-|ShellEx
| |ShellNew

I have no "shell" subkey and no "open" subkey. Must be a Windows XP thing.

RedWine's post included the following:

code:--------------------------------------------------------------------------------ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe" "path"
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myapp.exe" "" "$INSTDIR\myapp.exe"
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myapp.exe" "path" "$INSTDIR"--------------------------------------------------------------------------------


SAG47 replied with:

code:--------------------------------------------------------------------------------ReadRegStr $0 HKCR ".txt" ""--------------------------------------------------------------------------------

Which is how one uses "ReadRegStr to read what the value where txtfile under .txt is". I really didn't get that. Does this command return "txtfile" in $0? Are you thus stating that I would create a registry entry under my software type for a bogus type of file and create a key that would then be used for it only to serve as a validation tool?

What I'd really like to know is how to structure a few lines of NSIS code to write to an appropriate area of the registry some sort of code or file location or "Key", which I can then locate from my Visual Basic application and use to conform that the software is licensed. (In fact, how to accomplish that task from the executable using C, FORTRAN, or even Pascal would probably point me in the right direction with VB.) I know that NSIS is already creating registry entries based upon the script it generates for the software executable. What I need to do is to create some form of registry entry that can hold a serial number and/or a user name (or do I just point to a particular text file with my hidden and encrypted serial number?) Does that mean I create a file type ".bog" entry and a subkey that I can use as a serial number? I'd hate to think of how many ".bog" entries that might create.

The "tutorial" on the registry is a good start, but if anyone could reply directly to the request just stated, that would be most useful. This does bring up another question. If my software uses files of type ".xxx", does that mean I have to get NSIS to create something under like the ".txt" entry for the files of type ".xxx"?

Sorry for all the questions, but learning tends to be a two-way street.

Thank you.


Plz use the button with the symbol # when you add code, this thread is already huge thus dificult to read :-)

Well, try this, copy/paste this simple nsis script and save it as test.nsi, then compile it and execute it.
After execution open your registry and browse to:
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myapp.exe" to see the result.
Note that in NSIS you may type either HKEY_LOCAL_MACHINE or HKLM they are both correct.

outfile test.exe
InstallDir '$PROGRAMFILES\My Application'

section
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myapp.exe" "" "$INSTDIR\myapp.exe"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myapp.exe" "path" "$INSTDIR"
sectionend

Writing Registry Entry
HM NIS Edit 2.0.3 generated a file with the following entries:


WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\AppMainExe.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\AppMainExe.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"


(Hope the "[code ]" fixes the problems complained about.)

I don't doubt how the data is added to the registry. I really need some help identifying how to specifically add then read from a one of these keys in a manner that won't damage registry and that will serve as my serial number check. I'm a bit unsettled about the prospect of someone else having the same file name and me overwriting it in the registry. I also need to accomodate uninstalling the software without missing bits and pieces.

I imagine I'd just add one more line to the preceding as:


WriteRegStr ${PRODUCT_VALIDATE_ROOT_KEY} "${PRODUCT_VALIDATE_KEY}" "SERIAL_NUMBER" "${123456789}"


Of course, this is just a guess.

Thanks again!

DJ2006 plz, don't you see what's going on here?
It's getting even hard to follow the structure of this thread.
Please, download the attached below example, compile it, run it, and examine carefully the actions.
It's not going to harm you.
It is just a sample code to help understand the way NSIS uses to deal with registry.
Happy Holidays!


Wow!!!!!
Thank you! When I asked for a few lines of code, I had no idea you would provide this little gem. I'll study it, and attempt to execute it. Thank you so very much!


You're welcome!
Hopefully, that this piece of code would help you get some steps inside.

Happy Holidays!