Pages

Friday, January 11, 2002

Peoplecode Windows Registry Access

Windows Registry stores various settings about the Windows system and other applications. To be able to access these information provides greater capability of your Peoplecode applications. For example, only a small number of Peoplesoft’s own settings (through Configuration Manager) are available as system variables. But they are all accessible in registry. The following are typical registry settings for 7.5 PSTools:

This Peoplecode function ReadReg() will let you glance at all the ASCII registry data of installed software under HKEY_CURRENT_USER, which contains the sub-key Software that describes the current user's software settings and contains program-specific information previously stored in the Win.ini or private initialization files in Windows 3.x.
To use the function, set &SUBKEY to the path in registry, as shown on the status bar above, and set &VALNAME to the Value Name in question. The Value Data will be returned in &KEY_VAL. For example, to read the value of PS_HOME, use subkey “Software\PeopleSoft\PeopleTools\Release7.5\Process Scheduler” and Value Name “PS_HOME”. Be sure to include spaces where needed. If the data string is longer than 128 bytes, you need to increase the value of &KEY_LEN.


  • Copy the function declaration:
    Local number &H_REG_KEY;
    Declare Function RegOpenKeyExA Library "advapi32" (long Value As number,
    string Value As string, long Value As number, long Value As number,
    long Ref As number) Returns long As number;
    Declare Function RegQueryValueExA Library "advapi32" (long Value As
    number, string Value As string, long Value As number, long Ref As
    number, string Ref As string, long Ref As number)
    Returns long As number;
    Declare Function RegCloseKey Library "advapi32" (long Value As
    number) Returns long As number;
    
    Function ReadReg(&SUBKEY As string, &VALNAME As string,
    &KEY_VAL As string) Returns boolean;
    &HKEY_CURRENT_USER = - 2147483647;
    &KEY_QUERY_VALUE = 1;
    
    &RC = RegOpenKeyExA(&HKEY_CURRENT_USER, &SUBKEY, 0,
    &KEY_QUERY_VALUE, &H_REG_KEY);
    If &RC <>  0 Then
    MessageBox(48, "ReadReg", 0, 0, "Cannot open Registry");
    Return False;
    End-If;
    /*key value type is null-terminated string */
    &REG_SZ = 1;
    /* initialize string to 128 bytes */
    &KEY_LEN = 129;
    &KEY_VAL = Rept(" ", &KEY_LEN);
    &RC = RegQueryValueExA(&H_REG_KEY, &VALNAME, 0, &REG_SZ,
    &KEY_VAL, &KEY_LEN);
    If &RC <>  0 Then
    MessageBox(48, "ReadReg", 0, 0, "Cannot query Registry");
    Return False;
    End-If;
    &RC = RegCloseKey(&H_REG_KEY);
    Return True;
    End-Function;
    
  • Copy the following function call test:&SUBKEY = "Software\PeopleSoft\PeopleTools\release7.5\startup"; &VALNAME = "dbtype"; &KEY_VAL = ""; &XX = ReadReg(&SUBKEY, &VALNAME, &KEY_VAL); If &XX Then MessageBox(48, "ReadReg", 0, 0, &SUBKEY | "\" | &VALNAME | "=" | &KEY_VAL | "."); Else WinMessage("Fail"); End-If;
  • (This article was originally published on 1/11/02 at www.slerp.com for PSTools version 6,7.)
    
    
  •