Skip to main content

[archive] Getting a value from the Windows Registry

  • April 1, 2004
  • 13 replies
  • 0 views

[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.

13 replies

[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.
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.

[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.
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.

[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.
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.

[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.
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.)

[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.
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

[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.
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.

[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.
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.

[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.
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.

[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.
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

[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.
I cannot see that you set buflen. Other than that, the code I posted works, just compare the calls in the two yourself.

[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.
If you want to check it on the client, you would need to use "DISPLAY_" for all of these. Could that be the problem?

[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.
If you want to check it on the client, you would need to use "DISPLAY_" for all of these. Could that be the problem?

[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.
If you want to check it on the client, you would need to use "DISPLAY_" for all of these. Could that be the problem?