FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour registry sample
Posts: 107
Joined: Tue Apr 11, 2006 04:36 PM
registry sample
Posted: Wed Mar 14, 2007 06:54 PM

hi, someone has an simple sample to write to windows registry? thanks

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: registry sample
Posted: Wed Mar 14, 2007 09:02 PM
#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
Posts: 107
Joined: Tue Apr 11, 2006 04:36 PM
registry sample
Posted: Thu Mar 15, 2007 02:01 AM

Enrico, thanks.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
registry sample
Posted: Thu Mar 15, 2007 02:44 AM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion