How to dynamically set items and key values in the Registry when Using InstallShield for packaging

Source: Internet
Author: User

In version 11.5, registry functions do not change much.

Here I want to record the Registry issue during packaging, registry subitem and key, open registry (START-> Run, enter regedit, OK ), you can see many folder icons in the tree on the left. These are items. Click an item to view its key value on the right. Each item has a "default ", some items have many key values.

During packaging, we sometimes need to record a lot of things. Well, we need to record the types of installation files (server programs or client programs ), we need to record the software registration type (the test version is still the software already registered), we need to record the software installation path (so when we upgrade the software, our patches can be copied to the installation path by ourselves). We often like to use the registry to record many things. Here I will talk about two registration methods.

1. Items and key values to be registered are static

Static means all the items and keys to be registered. Their values are known when the installation package is created. We can set them directly in the is registry panel.

Assume that I want to create an item: HKEY_LOCAL_MACHINE // software // nnlltest. Under nnlltest, there are two string value keys: Install (record the installation path) soft (record that this software is a test version and the value is 0)

The procedure is as follows:

1. Click the Registry panel and expand default. You can see the five root types, which are fixed and unchanged.

2. Select HKEY_LOCAL_MACHINE, right-click, and choose new> key from the menu. Create a new key #1 item and change the name to "software"

3. Select software, right-click, select new-> key, and create a new item "New Key #1". Change the name to "nnlltest"

In this way, a HKEY_LOCAL_MACHINE // software // nnlltest item is created.

4. Select nnlltest, right-click, choose new-> string value from the menu, create a new key "new value #1", and change the name to "Install". In this way, a key is created, double-click the key value and enter <targetdir> in the "value data" text box.

<Targetdir> In is, it indicates the installation path.

5. Repeat Step 1 and change the name to "soft". Input "value data" to "0 ".

In this way, the Registry is created.

 

After installing the installation file, it will also be automatically generated in the registry according to the settings here. The registry keys and key values generated here will be uninstalled at the same time.

The preceding steps are five steps in total. You can also add a key value to your registry and then export the reg file. Use the import menu in the Registry panel for import. In section 11.5, on the registry panel, the Registry is in the upper left corner. You can copy your registry to the registry of the installation package in the lower left corner.

2. Items and key values to be registered are dynamic

Dynamic means the items and keys to be registered. Their values are unknown. They are determined by the user's selection and input values during user installation, at this time, we will use the registry function to register in the script.

I don't want to talk about registry functions. I don't know much about it. I want to learn how to download the Chinese version of the complete set of InstallShield internal database functions. Here I will record some of the things I used during my learning.

One of my posts asked: regdbgetkeyvalueex usage:

 

Syntax: regdbgetkeyvalueex (szkey, szname, nvtype, svvalue, nvsize );

Description: The regdbgetkeyvalueex function retrieves the value of a specific value under a specified item in the registry. InstallShield assumes that this item is a subitem under hkey_classes_root. You can use regdbsetdefaultroot to specify another key. Regdbgetkeyvalueex is a common registry-related function designed to work on all registry items, including those processed by special registry-related functions.

Parameter: szkey indicates the name of the item whose value is to be retrieved. Use a double backslash to separate different layers in the subitem. Szname specifies the Value Name of the value to be retrieved under szkey. The default value of the item to be retrieved, an empty string is passed. Nvtype returns one of the following predefined constants that identify the type of the data returned in svvalue: see the description in section 15.12. Svvalue returns the value specified by szkey and svname. Note that a numeric value is returned as a string. Nvsize is the size of the value returned in the svvalue in bytes.

Return Value: 0: indicates that the function successfully retrieves the value. <0: indicates that the function fails to retrieve the value.

 

In red, "items" refer to the items shown in the folder pictures on the left in the registry? The "data value" does not refer to the name in the "name, type, and data" list displayed on the right of the Registry?

After trying several calls, I encountered an error. What exactly are the words in the registry?

A:

Li Mu spoon 15:09:01
Regdbsetkeyvalueex (szkeyroot, "path", regdb_string, installdir,-1 );
Li Mu spoon 15:15:07
Szkey = "software // nnlltest"; this is the item you created.
You write the value to this place:
Software // nnlltest // ConA

These two statements teach me how to use regdbsetkeyvalueex.

1. Items created with installationinfo and key values created with regdbsetitem
The items created by installationinfo must be in HKEY_LOCAL_MACHINE]/software/Microsoft/Windows/CurrentVersion/APP paths. The function is

Function nnllreg ()
Number nitem;
String szcompany, szproduct, szversion, szproductkey, szvalue;
Begin
// Modify the Registry
// Under HKEY_LOCAL_MACHINE/software/Microsoft/Windows/CurrentVersion/APP paths/
// An item is created: nnll wants to add a key
// Two keys: Default and Path
// Uninstallable
Szcompany = "company name ";
Szproduct = "software name ";
Szversion = "1.0 ";
Szproductkey = "// nnll want to add a key ";
If (installationinfo (szcompany, szproduct, szversion, szproductkey) <0) then
MessageBox ("add item error", severe );
Else
// Add the key value under this item
// Default
Nitem = regdb_apppath_default;
Szvalue = targetdir + "// default ";
Regdbsetitem (nitem, szvalue );
// Path
Nitem = regdb_apppath;
Szvalue = targetdir;
Regdbsetitem (nitem, szvalue );
Endif;
End;

In this way, the registered registry is unloaded at the same time during the loading.

2. Use regdbsetkeyvalueex to register the item and key value in the specified path

Assume that I want to create an item: HKEY_LOCAL_MACHINE // software // nnlltest. Under nnlltest, there are two string value keys: ConA (record company name) SC (record whether the software is a client program or a server program)

① The dialog box for obtaining the company name and user name is generally automatically generated

Dlg_sdregisteruser:
Szmsg = "";
Sztitle = "";
// {Is_script_tag (dlg_sdregisteruser)
Nresult = sdregisteruser (sztitle, szmsg, szname, szcompany );
//} Is_script_tag (dlg_sdregisteruser)
If (nresult = back) goto dlg_sdlicense2;

② In the onfirstuibefore function, add a dialog box for the user to determine whether to install the server or client program.

// Add nnll to determine whether the server or workstation is installed
Selecttype:
Szmsg = "select the computer to install :";
Bvcheck1 = true;
Bvcheck2 = false;
Bvtype = true;
Nresult = askoptions (exclusive, szmsg, "server", bvcheck1, "workstation", bvcheck2 );
If (nresult = back) goto dlg_sdlicense2;
If bvcheck2 = true then
// Workstation, registry entry Server = 0
Bvtype = false;
Else
// Server, registry entry Server = 1
Bvtype = true;
Endif;
// Nnll modified

Oh, I forgot to mention that the szcompany and bvtype variables should be set to global variables.

③ Add a registry function

Function nnllreg ()
Number nrootkey, ntype, nsize;
String szkey, sznumname, sznumvalue, szclass;
Begin
// Modify the Registry
Nrootkey = HKEY_LOCAL_MACHINE;
Regdbsetdefaultroot (nrootkey); // set the root value to nrootkey
// Subitem Registration
Szkey = "software // nnlltest //";
If regdbkeyexist (szkey) <0 then
// "Software // nnlltest" does not exist. Create this item.
Regdbcreatekeyex (szkey ,"");
Endif;
// Initialize the public value of each key
Ntype = regdb_string;
Nsize =-1;
// Register the installation path
Sznumname = "Install ";
Sznumvalue = targetdir;
Regdbsetkeyvalueex (szkey, sznumname, ntype, sznumvalue, nsize );
// Set it to an unregistered version
Sznumname = "soft ";
Sznumvalue = "0 ";
If regdbkeyexist (szkey) <0 then
// If This item does not exist, register it. If yes, skip
Regdbsetkeyvalueex (szkey, sznumname, ntype, sznumvalue, nsize );
Regdbcreatekeyex (szkey, szclass );
Endif;
// Register the company name
Sznumname = "cona ";
Sznumvalue = szcompany;
Regdbsetkeyvalueex (szkey, sznumname, ntype, sznumvalue, nsize );
// Register the program type
Sznumname = "SC ";
If bvtype then
Sznumvalue = "S ";
Else
Sznumvalue = "C ";
Endif;
Regdbsetkeyvalueex (szkey, sznumname, ntype, sznumvalue, nsize );
End;

④ Call this custom function to generate the entry and key value in the registry at the end of the Installation

Prototype nnllreg (); // declare a function
Function onend ()
Begin
// Modify the Registry
Nnllreg ();
End;

In this way, the registered items and key values are retained during uninstallation, dynamic values are deleted, static values are retained, and re-installation is performed, the value is updated.

The last thing I want to talk about is the regdbsetkeyvalueex function, because there is a sentence in the Chinese version of the complete set of InstallShield internal library functions.

Szname specifies the value of the number of values to be set. To set the default value of the item specified in szkey, an empty string is passed to this parameter.

I have poor reading ability, so I have always set szname = "", so I have never registered a key value. I am registering a subitem, And I have recorded two sentences from Li Mu spoon, I think of these two sentences.

If sznumname = "" is created, it is a subitem, szkey, and the default value is sznumvalue.

If sznumname = "Name of the key", the key value under szkey is created. The default value is sznumvalue.

In the help of is, there is an example like this:

// Create a key to test.
Szkey = "testkey ";
If (regdbcreatekeyex (szkey, "") <0) then
MessageBox ("regdbcreatekeyex failed.", severe );
Abort;
Endif;
// Set up parameters for call to regdbsetkeyvalueex.
Sznumname = "testvalue ";
Sznumbervalue = "12345 ";
Ntype = regdb_number;
Nsize =-1;
// Set a key name and a value associated with it.
If (regdbsetkeyvalueex (szkey, sznumname, ntype, sznumvalue, nsize) <0) then
MessageBox ("regdbsetkeyvalueex failed.", severe );
Abort;
Else
// Display what regdbsetkeyvalueex has done.
Szmsg = "% s set to: % s ";
Sprintfbox (information, title, szmsg, sznumname, sznumvalue );
Endif;

If I read this example when I pressed F1 in the last week, I will also think about how to use it. I didn't, because I thought I had a complete set of InstallShield internal library functions.

The best help is F1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.