registry sample

Post Reply
User avatar
Nop
Posts: 107
Joined: Tue Apr 11, 2006 4:36 pm
Location: Uberaba/Brazil

registry sample

Post by Nop »

hi, someone has an simple sample to write to windows registry? thanks
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: registry sample

Post by Enrico Maria Giordano »

Code: Select all

#define HKEY_CURRENT_USER 2147483649

#define KEY_ALL_ACCESS 983103

#define REG_SZ 1


STATIC FUNCTION PDFGETOPTION( cKey )

    LOCAL hKey := 0

    LOCAL nType := REG_SZ

    LOCAL cData := SPACE( 256 )

    LOCAL nSize := LEN( cData )

    REGOPENKEY( HKEY_CURRENT_USER, "Software\PDFCreator\Program", 0, KEY_ALL_ACCESS, @hKey )

    REGQUERYVALUE( hKey, cKey, 0, @nType, @cData, @nSize )

    REGCLOSEKEY( hKey )

    RETURN LEFT( cData, AT( CHR( 0 ), cData ) - 1 )


STATIC FUNCTION PDFSETOPTION( cKey, cValue )

    LOCAL hKey := 0

    LOCAL nType := REG_SZ

    LOCAL nSize := LEN( cValue )

    REGOPENKEY( HKEY_CURRENT_USER, "Software\PDFCreator\Program", 0, KEY_ALL_ACCESS, @hKey )

    REGSETVALUE( hKey, cKey, 0, nType, cValue, nSize )

    REGCLOSEKEY( hKey )

    RETURN NIL


DLL32 STATIC FUNCTION REGOPENKEY( hKey AS LONG, cSubKey AS LPSTR, nOptions AS DWORD, nSamDesired AS DWORD, @nHandle AS PTR ) AS LONG;
      PASCAL FROM "RegOpenKeyExA" LIB "advapi32.dll"

DLL32 STATIC FUNCTION REGQUERYVALUE( hKey AS LONG, cValueName AS LPSTR, nReserved AS LONG, @nType AS PTR, @cData AS LPSTR, @nSize AS PTR ) AS LONG;
      PASCAL FROM "RegQueryValueExA" LIB "advapi32.dll"

DLL32 STATIC FUNCTION REGSETVALUE( hKey AS LONG, cValueName AS LPSTR, nReserved AS LONG, nType AS DWORD, cData AS LPSTR, nData AS DWORD ) AS LONG;
      PASCAL FROM "RegSetValueExA" LIB "advapi32.dll"

DLL32 STATIC FUNCTION REGCLOSEKEY( hKey AS LONG ) AS LONG;
      PASCAL FROM "RegCloseKey" LIB "advapi32.dll"
EMG
User avatar
Nop
Posts: 107
Joined: Tue Apr 11, 2006 4:36 pm
Location: Uberaba/Brazil

Post by Nop »

Enrico, thanks.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Nop,

Be sure to check out the new security issues with writing to the registry under Vista. Here is a good place to start:

http://windowsconnected.com/blogs/jerry ... 19/86.aspx

James
Post Reply