Highlighted
Absent Member.
Absent Member.
1627 views

[archive] Getting a value from the Windows Registry

[Migrated content. Thread originally posted on 31 March 2004]

How do you retrieve a value from the Registry? I have tried something like the following example, which tries to retrieve the path of Iexplore.exe, but it just returns a status code 2.


           CALL "REG_QUERY_VALUE"
               USING HKEY_LOCAL_MACHINE,
                     WS-APP-PATH,
                     WS-RETURN-SIZE,
                     "Software\Microsoft\Windows\CurrentVersion\App Path
      -              "s\IEXPORE.EXE"
                     WS-KEY
               GIVING WS-REG-STATUS
           END-CALL.
0 Likes
7 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting a value from the Windows Registry

A couple of issues here.

First, you mix the syntax of REG_QUERY_VALUE_EX and REG_QUERY_VALUE.

Second, you have spelled the IEXPLORE.EXE wrong.

The error 2 btw means not found.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting a value from the Windows Registry

Thanks! My problem was the missing "L" in IEXPLORE.EXE. I knew I needed a second pair of eyes to detect the dumb mistake.

(That WS-KEY argument was supposed to be deleted after I substituted the string literal for the example.)
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting a value from the Windows Registry

I am using similiar code to above and always getting a 0000 return code but my pathname appears to get nothing in it when I try to display/use it.

77 BufLen usage unsigned-int.
77 PathName pic x(256).
77 REG-STATUS-CODE PIC S9(4).

CALL "REG_QUERY_VALUE_EX" USING HKEY_CURRENT_USER,
PathName, BufLen, "\Environment", "Temp"
GIVING REG-STATUS-CODE
end-call

PathName should have the value of the Temp reg key, correct?

Note, running thin client v7.2
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting a value from the Windows Registry

I am using similiar code to above and always getting a 0000 return code but my pathname appears to get nothing in it when I try to display/use it.


The registry need to be opened first.


       IDENTIFICATION               DIVISION.
       PROGRAM-ID.                  TEMPLATE.
       ENVIRONMENT                  DIVISION.
       CONFIGURATION                SECTION.
       SPECIAL-NAMES.
       WORKING-STORAGE SECTION.
       77 MY-OPEN-KEY               USAGE UNSIGNED-LONG.
       77 BUFLEN                    USAGE UNSIGNED-INT.
       77 PATHNAME                  PIC X(256).
       77 REG-STATUS-CODE           PIC S9(4).
      *Values from acugui.def     
       78  HKEY_CURRENT_USER        VALUE 2147483649.
       78  REG_SZ                   VALUE 1.
       78  REG_EXPAND_SZ            VALUE 2.
       78  KEY_QUERY_VALUE          VALUE 1.
       PROCEDURE DIVISION.
       MAIN-LOGIC.
           SET     BUFLEN TO SIZE OF PATHNAME
           CALL    "REG_OPEN_KEY_EX" USING
                     HKEY-CURRENT-USER
                     "Environment"
                     KEY-QUERY-VALUE
                     MY-OPEN-KEY
                     GIVING REG-STATUS-CODE

           CALL    "REG_QUERY_VALUE_EX" USING
                   MY-OPEN-KEY
                   "Temp"
                   REG-EXPAND-SZ
                   PATHNAME
                   BUFLEN
                   GIVING REG-STATUS-CODE
           CALL    "REG-CLOSE-KEY"  USING MY-OPEN-KEY
           EXIT    PARAGRAPH.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting a value from the Windows Registry

I was already doing the open and close. My return codes on the open and the query are both 0000, but I do not get any value back from teh query in PATHNAME. Here is the whole segment, please tell me if you see anything wrong... thanks. BTW, I am using thin client version 7.2. I'm guessing it's a thin client issue but I'm not sure how to code around it for this. Compiler is 6.1.

(note that I did not include my display logic for return codes or error handling logic)

77 BUFLEN usage unsigned-int.
77 PATHNAME pic x(256).
77 MY-REGISTRY-HANDLE USAGE UNSIGNED-LONG.
77 REG-STATUS-CODE PIC S9(4).

CALL "REG_OPEN_KEY_EX" USING
HKEY_CURRENT_USER,
"Environment",
KEY-QUERY-VALUE
MY-REGISTRY-HANDLE
GIVING REG-STATUS-CODE
END-CALL
CALL "REG_QUERY_VALUE_EX" USING
MY-REGISTRY-HANDLE,
"TEMP"
REG-EXPAND-SZ,
PATHNAME,
BUFLEN,
GIVING REG-STATUS-CODE
END-CALL
CALL "REG_CLOSE_KEY" USING
MY-REGISTRY-HANDLE
END-CALL
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting a value from the Windows Registry

I cannot see that you set buflen. Other than that, the code I posted works, just compare the calls in the two yourself.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting a value from the Windows Registry

If you want to check it on the client, you would need to use "DISPLAY_" for all of these. Could that be the problem?
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.