Guidance
指路人
g.yi.org
software / rapidq / Examples / Registry & INI / Win32API Registry / Registry.BAS

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
     $OPTIMIZE ON
'$APPTYPE GUI
     $TYPECHECK ON
     $ESCAPECHARS ON

     CONST GMEM_FIXED=0
     CONST GMEM_MOVEABLE=2
     CONST GMEM_ZEROINIT=64
     CONST GMEM_INVALID_HANDLE=&H8000
     CONST HKEY_CLASSES_ROOT=&H80000000
     CONST HKEY_CURRENT_USER=&H80000001
     CONST HKEY_LOCAL_MACHINE=&H80000002
     CONST HKEY_USERS=&H80000003
     CONST HKEY_PERFORMANCE_DATA=&H80000004
     CONST HKEY_CURRENT_CONFIG=&H80000005
     CONST HKEY_DYN_DATA=&H80000006
     CONST REG_OPTION_NON_VOLATILE=0     ' Key is Saved by the Registry.
     CONST REG_OPTION_VOLATILE=1         ' Key is not Saved by the Registry.
     CONST KEY_QUERY_VALUE=1
     CONST KEY_SET_VALUE=2
     CONST KEY_CREATE_SUB_KEY=4
     CONST KEY_ENUMERATE_SUB_KEYS=8
     CONST KEY_NOTIFY=16
     CONST KEY_CREATE_LINK=32
     CONST KEY_READ=KEY_QUERY_VALUE OR KEY_ENUMERATE_SUB_KEYS OR KEY_NOTIFY
     CONST KEY_WRITE=KEY_SET_VALUE OR KEY_CREATE_SUB_KEY
     CONST KEY_ALL_ACCESS=KEY_QUERY_VALUE OR KEY_ENUMERATE_SUB_KEYS OR KEY_NOTIFY OR KEY_CREATE_SUB_KEY OR KEY_CREATE_LINK OR KEY_SET_VALUE
     CONST ERROR_SUCCESS=0
     CONST REG_CREATED_NEW_KEY=1
     CONST REG_OPENED_EXISTING_KEY=2
     CONST REG_NONE=0             ' No defined Value Type.
     CONST REG_SZ=1               ' Unicode/Ansi String.
     CONST REG_EXPAND_SZ=2        ' Unicode/Ansi Environment-Path String.
     CONST REG_BINARY=3
     CONST REG_DWORD=4
     CONST REG_DWORD_LITTLE_ENDIAN=4  ' 32-bit number
     CONST REG_DWORD_BIG_ENDIAN=5     ' 32-bit number
     CONST REG_LINK=6                 ' Symbolic Link (unicode)
     CONST REG_MULTI_SZ=7             ' Array of Strings, 2 NULLs each String.
     CONST REG_RESOURCE_LIST=8        ' Device-Drive Resource List.
     CONST REG_NOTIFY_CHANGE_NAME=1
     CONST REG_NOTIFY_CHANGE_ATTRIBUTES=2
     CONST REG_NOTIFY_CHANGE_LAST_SET=4
     CONST REG_NOTIFY_CHANGE_SECURITY=8
     CONST WAIT_OBJECT_0=0
     CONST WAIT_TIMEOUT=&H102
     CONST WAIT_ABANDONED=128
     CONST WAIT_FAILED=&HFFFFFFFF
     CONST INFINITE=&HFFFF
     CONST ERROR_NO_MORE_ITEMS=259
     CONST ERROR_MORE_DATA=234

' Registry.BAS CONST Values.
     CONST WATCH_KEY_ONLY=0
     CONST WATCH_KEYS_VALUES=1

     DECLARE FUNCTION CloseHandle LIB "kernel32.dll" ALIAS "CloseHandle" (hObject AS LONG) AS LONG
     DECLARE SUB CopyMemory LIB "kernel32.dll" ALIAS "RtlMoveMemory" (BYVAL dest AS LONG, BYVAL source AS LONG, BYVAL numBytes AS LONG)
     DECLARE FUNCTION CreateEvent LIB "kernel32.dll" ALIAS "CreateEventA" (securityAttrs AS LONG, manualReset AS LONG, initialState AS LONG, eventName AS STRING) AS LONG
     DECLARE FUNCTION GetLastError LIB "kernel32.dll" ALIAS "GetLastError" () AS LONG
     DECLARE FUNCTION GlobalAlloc LIB "kernel32.dll" ALIAS "GlobalAlloc" (flags AS LONG, numBytes AS LONG) AS LONG
     DECLARE FUNCTION GlobalFree LIB "kernel32.dll" ALIAS "GlobalFree" (hMem AS LONG) AS LONG
     DECLARE FUNCTION GlobalLock LIB "kernel32.dll" ALIAS "GlobalLock" (hMem AS LONG) AS LONG
     DECLARE FUNCTION GlobalUnlock LIB "kernel32.dll" ALIAS "GlobalUnlock" (hMem AS LONG) AS LONG
     DECLARE FUNCTION RegCloseKey LIB "advapi32.dll" ALIAS "RegCloseKey" (rootKey AS LONG) AS LONG
     DECLARE FUNCTION RegConnectRegistry LIB "advapi32.dll" ALIAS "RegConnectRegistryA" (machineName AS STRING, rootKey AS LONG, result AS LONG) AS LONG
     DECLARE FUNCTION RegCreateKeyEx LIB "advapi32.dll" ALIAS "RegCreateKeyExA" (rootKey AS LONG, subKey AS STRING, reserved AS LONG, class AS STRING, options AS LONG, access AS LONG, security AS LONG, handle AS LONG, status AS LONG) AS LONG
     DECLARE FUNCTION RegDeleteKey LIB "advapi32.dll" ALIAS "RegDeleteKeyA" (rootKey AS LONG, subKey AS STRING) AS LONG
     DECLARE FUNCTION RegDeleteValue LIB "advapi32.dll" ALIAS "RegDeleteValueA" (rootKey AS LONG, valueName AS STRING) AS LONG
     DECLARE FUNCTION RegEnumKeyEx LIB "advapi32.dll" ALIAS "RegEnumKeyExA" (rootKey AS LONG, index AS LONG, keyBuf AS LONG, kbSize AS LONG, reserved AS LONG, classBuf AS LONG, cbSize AS LONG, lastWriteTime AS LONG) AS LONG
     DECLARE FUNCTION RegEnumValue LIB "advapi32.dll" ALIAS "RegEnumValueA" (rootKey AS LONG, index AS LONG, valBuf AS LONG, vbSize AS LONG, reserved AS LONG, valueType AS LONG, valueData AS LONG, vdSize AS LONG) AS LONG
     DECLARE FUNCTION RegNotifyChangeKeyValue LIB "advapi32.dll" ALIAS "RegNotifyChangeKeyValue" (rootKey AS LONG, watchSubtree AS LONG, notifyFilter AS LONG, hEvent AS LONG, fAsynchronus AS LONG) AS LONG
     DECLARE FUNCTION RegOpenKeyEx LIB "advapi32.dll" ALIAS "RegOpenKeyExA" (rootKey AS LONG, subKey AS STRING, options AS LONG, access AS LONG, status AS LONG) AS LONG
     DECLARE FUNCTION RegQueryInfoKey LIB "advapi32.dll" ALIAS "RegQueryInfoKeyA" (rootKey AS LONG, buffer AS STRING, bufsize AS LONG, reserved AS LONG, subKeys AS LONG, maxSubKeyLen AS LONG, maxClassLen AS LONG, values AS LONG, maxValueNameLen AS LONG, maxValueLen AS LONG, security AS LONG, lastWriteTime AS LONG) AS LONG
     DECLARE FUNCTION RegQueryValueEx LIB "advapi32.dll" ALIAS "RegQueryValueExA" (rootKey AS LONG, valueName AS STRING, reserved AS LONG, valueType AS LONG, buffer AS LONG, bufsize AS LONG) AS LONG
     DECLARE FUNCTION RegSetValueEx LIB "advapi32.dll" ALIAS "RegSetValueExA" (rootKey AS LONG, valueName AS STRING, reserved AS LONG, valueType AS LONG, valueData AS LONG, valueSize AS LONG) AS LONG
     DECLARE FUNCTION WaitForSingleObject LIB "kernel32.dll" ALIAS "WaitForSingleObject" (hHandle AS LONG, timeout AS LONG) AS LONG

' Registry Variables.
     DIM key_Handle AS LONG, key_Status AS LONG, key_Root AS LONG
     DIM key_Type AS LONG, compReg_Handle AS LONG, event_Handle AS LONG
     DIM mem_Lock AS LONG, mem_Memory AS LONG, mem_Default AS LONG
     DIM mem_Offset AS LONG
     DIM numSubKeys AS LONG, maxSubKey AS LONG, maxClass AS LONG
     DIM numValues AS LONG, maxValueName AS LONG, maxValueData AS LONG
     DIM securityLength AS LONG

' Generic Variables.
     DIM rtn AS LONG, rtnval AS LONG, stg$ AS STRING, count AS LONG
     DIM FLong AS LONG, FWord AS WORD, FByte AS BYTE, FDWord AS LONG
     DIM stgs$(0 TO 10) AS STRING, stgbuf$ AS STRING

     stgbuf$=STRING$(256, 65)

     key_Root=HKEY_LOCAL_MACHINE
     key_Handle=0
     key_Status=0
     key_Type=0
     compReg_Handle=0

     SUB UnLock_DefaultMemory
      IF mem_Lock<>0 THEN
       rtn=GlobalUnlock(mem_Lock)
       IF ((rtn=0) AND (GetLastError()=0)) THEN
'MEM UNLOCKED
       ELSE
'MEM NOT UNLOCK
       END IF
      END IF
     END SUB

     SUB Free_DefaultMemory
      IF mem_Memory<>0 THEN
       rtn=GlobalFree(mem_Memory)
       IF rtn=0 THEN
'MEM FREED
       ELSE
'MEM NOT FREED
       END IF
      END IF
     END SUB

     SUB Alloc_DefaultMemory(bufsize AS LONG)
      mem_Lock=0
      mem_Memory=0
      mem_Default=0
      mem_Memory=GlobalAlloc(GMEM_MOVEABLE OR GMEM_ZEROINIT, bufsize)
      IF mem_Memory<>0 THEN
       mem_Lock=GlobalLock(mem_Memory)
       IF mem_Lock<>0 THEN
        mem_Default=mem_Lock

       END IF
      END IF
     END SUB

' Delete a SubKey.
     SUB Reg_DeleteKey(key_Name$ AS STRING)
      IF key_Handle<>0 THEN
       rtn=RegDeleteKey(key_Root, key_Name$)
       IF rtn=ERROR_SUCCESS THEN
        SHOWMESSAGE("Key - Deleted")
       ELSE
        SHOWMESSAGE("DeleteKey - Failed")
       END IF
      END IF
     END SUB

' Delete a Value from a SubKey.
     SUB Reg_DeleteValue(key_Name$ AS STRING)
      IF key_Handle<>0 THEN
       rtn=RegDeleteValue(key_Handle, key_Name$)
       IF rtn=ERROR_SUCCESS THEN
        SHOWMESSAGE("Value - Deleted")
       ELSE
        SHOWMESSAGE("DeleteValue - Failed")
       END IF
      END IF
     END SUB

' Connect to another machine`s Registry.
     SUB Reg_ConnectToOtherRegistry(machine_Name$ AS STRING, rootType AS LONG)
      rtn=RegConnectRegistry(machine_Name$, rootType, VARPTR(compReg_Handle))
      IF rtn=ERROR_SUCCESS THEN
       SHOWMESSAGE("Connected")
      ELSE
       SHOWMESSAGE("NOT Connected")
      END IF
     END SUB

' Query (Get) Information about a SubKey.
     SUB Reg_QueryKeyInfo
      IF key_Handle<>0 THEN
       rtn=RegQueryInfoKey(key_Handle, mem_Default, VARPTR(rtnval), 0, VARPTR(numSubKeys), VARPTR(maxSubKey), VARPTR(maxClass), VARPTR(numValues), VARPTR(maxValueName), VARPTR(maxValueData), VARPTR(securityLength), mem_Default+200)
       IF rtn=ERROR_SUCCESS THEN
        SHOWMESSAGE("Key Info - Queried")
       ELSE
        SHOWMESSAGE("Key Info - Failed")
       END IF
      END IF
     END SUB

' Query a Value in a SubKey.
     SUB Reg_QueryValue(key_Name$ AS STRING)
      IF key_Handle<>0 THEN
       rtn=RegQueryValueEx(key_Handle, key_Name$, 0, VARPTR(key_Type), mem_Default, VARPTR(rtnval))
       IF rtn=ERROR_SUCCESS THEN
        SHOWMESSAGE("Value - Queried")
       ELSE
        SHOWMESSAGE("QueryValue - Failed")
       END IF
      END IF
     END SUB

' Enumerate a SubKey.
     SUB Reg_EnumKey(index AS LONG)
      IF key_Handle<>0 THEN
       rtn=RegEnumKeyEx(key_Handle, index, mem_Default, VARPTR(FLong), 0, mem_Default+40, VARPTR(rtnval), mem_Default+80)
       IF rtn=ERROR_SUCCESS THEN
        SHOWMESSAGE("EnumKey - Queried")
       ELSE
        IF rtn=ERROR_NO_MORE_ITEMS THEN
         SHOWMESSAGE("EnumKey - No More SubKeys To Enumerate")
        ELSE
         SHOWMESSAGE("EnumKey - Failed")
        END IF
       END IF
      END IF
     END SUB

' Enumerate a Value.
     SUB Reg_EnumValue(index AS LONG)
      IF key_Handle<>0 THEN
       rtn=RegEnumValue(key_Handle, index, mem_Default, VARPTR(FLong), 0, VARPTR(key_Type), mem_Default+40, VARPTR(rtnval))
       IF rtn=ERROR_SUCCESS THEN
        SHOWMESSAGE("EnumValue - Queried")
       ELSE
        IF rtn=ERROR_NO_MORE_ITEMS THEN
         SHOWMESSAGE("EnumValue - No More SubKeys To Enumerate")
        ELSE
         SHOWMESSAGE("EnumValue - Failed"+"  "+STR$(rtn))
        END IF
       END IF
      END IF
     END SUB

' Closes, but does not delete, another computer`s RootKey (Handle).
     SUB Reg_CloseOtherRegistry
      IF compReg_Handle<>0 THEN
       rtn=RegCloseKey(compReg_Handle)
       IF rtn=ERROR_SUCCESS THEN
        SHOWMESSAGE("Key - Closed")
       ELSE
        SHOWMESSAGE("CloseKey - Failed")
       END IF
      END IF
     END SUB

' Closes an Event Key.
     SUB Reg_CloseEvent
      IF event_Handle<>0 THEN
       rtn=CloseHandle(event_Handle)
       IF rtn<>0 THEN
        SHOWMESSAGE("Event - Closed")
       ELSE
        SHOWMESSAGE("CloseEvent - Failed")
       END IF
      END IF
     END SUB

' Closes, but does not delete, a SubKey.
     SUB Reg_CloseKey
      IF key_Handle<>0 THEN
       rtn=RegCloseKey(key_Root)
       IF rtn=ERROR_SUCCESS THEN
        SHOWMESSAGE("Key - Closed")
       ELSE
        SHOWMESSAGE("CloseKey - Failed")
       END IF
      END IF
     END SUB

' Watch SubKeys and/or Values for changes.
     SUB Reg_Notify(watchFlag AS LONG, notifyFlags AS LONG, asyncFlag AS LONG)
      IF key_Handle<>0 THEN
       event_Handle=CreateEvent(0, 1, 0, 0)
       IF event_Handle<>0 THEN
        rtn=RegNotifyChangeKeyValue(key_Handle, watchFlag, notifyFlags, event_Handle, asyncFlag)
        IF rtn=ERROR_SUCCESS THEN
         rtn=WaitForSingleObject(event_Handle, INFINITE)
         IF rtn<>WAIT_FAILED THEN
          SHOWMESSAGE("WaitObject - Finished")
         ELSE
          SHOWMESSAGE("WaitObject - Failed")
         END IF
        ELSE
         SHOWMESSAGE("Notify - Failed")
        END IF
       ELSE
        SHOWMESSAGE("CreateEvent - Failed")
       END IF
      END IF
     END SUB

' Set an Array of String Values in a SubKey.
     SUB Reg_SetStringArrayValues(value_Name$ AS STRING, bufsize AS LONG)
      rtn=RegSetValueEx(key_Handle, value_Name$, 0, REG_MULTI_SZ, mem_Default, bufsize)
      IF rtn=ERROR_SUCCESS THEN
       SHOWMESSAGE("String Array Values - Set")
      ELSE
       SHOWMESSAGE("String Array Values - NOT Set")
      END IF
     END SUB

' Set a STRING Value in a SubKey.
     SUB Reg_SetStringValue(value_Name$ AS STRING, bufsize AS LONG)
      rtn=RegSetValueEx(key_Handle, value_Name$, 0, REG_SZ, mem_Default, bufsize)
      IF rtn=ERROR_SUCCESS THEN
       SHOWMESSAGE("String Value - Set")
      ELSE
       SHOWMESSAGE("String Value - NOT Set")
      END IF
     END SUB

' Set a BINARY Value in a SubKey.
     SUB Reg_SetBinaryValue(value_Name$ AS STRING, bufsize AS LONG)
      rtn=RegSetValueEx(key_Handle, value_Name$, 0, REG_BINARY, mem_Default, bufsize)
      IF rtn=ERROR_SUCCESS THEN
       SHOWMESSAGE("Binary Value - Set")
      ELSE
       SHOWMESSAGE("Binary Value - NOT Set")
      END IF
     END SUB

' Set a DWORD Value in a SubKey.
     SUB Reg_SetDWordValue(value_Name$ AS STRING)
      rtn=RegSetValueEx(key_Handle, value_Name$, 0, REG_DWORD, mem_Default, 4)
      IF rtn=ERROR_SUCCESS THEN
       SHOWMESSAGE("DWord Value - Set")
      ELSE
       SHOWMESSAGE("DWord Value - NOT Set")
      END IF
     END SUB

' Open a SubKey.
     SUB Reg_OpenKey(key_Name$ AS STRING, accessOptions AS LONG)
      rtn=RegOpenKeyEx(key_Root, key_Name$, 0, accessOptions, VARPTR(key_Handle))
      IF rtn=ERROR_SUCCESS THEN
       SHOWMESSAGE("Key - Opened")
      ELSE
       SHOWMESSAGE("Key - NOT Opened")
      END IF
     END SUB

' Create and/or Open a SubKey.
     SUB Reg_CreateKey(key_Name$ AS STRING, className$ AS STRING, saveOption AS LONG, accessOptions AS LONG)
      rtn=RegCreateKeyEx(key_Root, key_Name$, 0, className$, saveOption, accessOptions, 0, VARPTR(key_Handle), VARPTR(key_Status))
      IF rtn=ERROR_SUCCESS THEN
       IF key_Status=REG_CREATED_NEW_KEY THEN
        SHOWMESSAGE("Key - Created")
       ELSE
        SHOWMESSAGE("Key - Opened, as it already exists")
       END IF
      ELSE
       key_Handle=0
       SHOWMESSAGE("Key - NOT Created")
      END IF
     END SUB

' Allocate a default buffer for Registry calls.
     Alloc_DefaultMemory(300)


' Create a new SubKey.
     Reg_CreateKey("Software\\LanguageGUI", "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS)

' Open a SubKey if it was newly created, as Newly Created SubKeys are
' not opened automatically.
     IF key_Status=REG_CREATED_NEW_KEY THEN
      Reg_OpenKey("Software\\LanguageGUI", KEY_ALL_ACCESS)
     END IF

' Set a DWORD Value in a SubKey.
     FDWord=8
     CopyMemory mem_Default, VARPTR(FDWord), 4
     Reg_SetDWordValue("DWord")

' Set a Binary Value in a SubKey.
     FDWord=&HFFFFFFFF
     CopyMemory mem_Default, VARPTR(FDWord), 4
     FWord=&H0907
     CopyMemory mem_Default+4, VARPTR(FWord), 2
     stg$="Registry BINARY Test"+CHR$(0)
     CopyMemory mem_Default+6, VARPTR(stg$), LEN(stg$)
     Reg_SetBinaryValue("Binary", 26)

' Set a String Value in a SubKey.
     stg$="Registry STRING Test"+CHR$(0)             ' Remember the Chr$(0).
     CopyMemory mem_Default, VARPTR(stg$), LEN(stg$)
     Reg_SetStringValue("String", LEN(stg$))

' Set an Array of String Values in a SubKey. Remember to put the two
' Chr$(0)`s at the end of each String.
     mem_Offset=0
     FOR count=0 TO 9
      stgs$(count)=STRING$(10, 48+count)+CHR$(0)+CHR$(0)
      CopyMemory mem_Default+mem_Offset, VARPTR(stgs$(count)), LEN(stgs$(count))
      mem_Offset=mem_Offset+LEN(stgs$(count))
     NEXT
     Reg_SetStringArrayValues("StringArray", mem_Offset)

' Query (Get) a DWord Value from a SubKey.
     rtnval=4
     Reg_QueryValue("Dword")
     CopyMemory VARPTR(FDWord), mem_Default, 4
     SHOWMESSAGE("Value: "+HEX$(FDWord)+" "+STR$(rtnval))

' Query (Get) a Binary Value from a SubKey.
     rtnval=200
     Reg_QueryValue("Binary")
' Note. Here it is assumed you know what is in the Binary data. I.e You
' set the Binary data yourself, you know the data contains a DEVMODE
' structure from WIN32API, etc. Thus. You should know how to retreive
' (Peek) that Binary data.

' Query (Get) a String Value from a SubKey. Note. As I do not want to
' alter the contents of mem_Default or stgbuf$, as there may be other
' valid data following, Mid$() is used to avoid poking a Chr$(0) into
' mem_Default or stgbuf$ in order to make a NULL String.
     rtnval=40
     Reg_QueryValue("String")
     CopyMemory VARPTR(stgbuf$), mem_Default, rtnval
     stg$=MID$(stgbuf$, 0, rtnval)
     SHOWMESSAGE("String Value: "+stg$)

' Query (Get) an Array of String Values from a SubKey.
     rtnval=200
     Reg_QueryValue("StringArray")
     mem_Offset=0
     FOR count=0 TO 9
      stgs$(count)=VARPTR$(mem_Default+mem_Offset)
      mem_Offset=mem_Offset+LEN(stgs$(count))+2
      SHOWMESSAGE("String Array Value: "+stgs$(count))
     NEXT

' Delete a SubKey.
'Reg_DeleteValue("DWord")

' Watch a SubKey and/or its Values for changes.
'Reg_Notify(WATCH_KEYS_VALUES, REG_NOTIFY_CHANGE_NAME OR REG_NOTIFY_CHANGE_LAST_SET, 1)

' Close a SubKey.
     Reg_CloseKey

' Close the Handle of the Notification Event.
'Reg_CloseEvent

' Get the Current User.
     Reg_OpenKey("System\\CurrentControlSet\\Control", KEY_ALL_ACCESS)
     rtnval=40
     Reg_QueryValue("Current User")
     CopyMemory VARPTR(stgbuf$), mem_Default, rtnval
     stg$=MID$(stgbuf$, 0, rtnval)
     SHOWMESSAGE("Current User: "+stg$)

     Reg_CloseKey

' Connect to another machine`s Registry.
'Reg_ConnectToOtherRegistry("", HKEY_USERS)
'Reg_CloseOtherRegistry

     Reg_OpenKey("Software\\LanguageGUI", KEY_ALL_ACCESS)

' Query (Get) Information about a SubKey.
     FLong=0
     CopyMemory mem_Default, VARPTR(FLong), 4
     CopyMemory mem_Default+4, VARPTR(FLong), 4
     CopyMemory mem_Default+8, VARPTR(FLong), 4
     rtnval=200
     Reg_QueryKeyInfo
     stg$=VARPTR$(mem_Default)
     SHOWMESSAGE("Class Name: "+stg$)
     stg$=HEX$(numSubKeys)
     SHOWMESSAGE("Number of SubKeys: "+stg$)
     stg$=HEX$(maxSubKey)
     SHOWMESSAGE("Longest Name used by a SubKey, Including this SubKey: "+stg$)
     stg$=HEX$(maxClass)
     SHOWMESSAGE("Longest Name used by a Class: "+stg$)
     stg$=HEX$(numValues)
     SHOWMESSAGE("Number of Values in this Opened Key: "+stg$)
     stg$=HEX$(maxValueName)
     SHOWMESSAGE("Longst Name used by a Value in this SubKey: "+stg$)
     stg$=HEX$(maxValueData)
     SHOWMESSAGE("Value with Most Data in this SubKey: "+stg$)
     stg$=HEX$(numSubKeys)
     SHOWMESSAGE("Length of Security Descriptor: "+stg$)
     CopyMemory VARPTR(FLong), mem_Default+200, 4
     SHOWMESSAGE(HEX$(FLong))
     CopyMemory VARPTR(FLong), mem_Default+204, 4
     SHOWMESSAGE(HEX$(FLong))

     Reg_CloseKey

     Reg_OpenKey("Software\\LanguageGUI", KEY_ALL_ACCESS)

     FLong=0
     CopyMemory mem_Default, VARPTR(FLong), 4
     CopyMemory mem_Default+4, VARPTR(FLong), 4
     CopyMemory mem_Default+8, VARPTR(FLong), 4
     CopyMemory mem_Default+40, VARPTR(FLong), 4
     CopyMemory mem_Default+44, VARPTR(FLong), 4
     CopyMemory mem_Default+48, VARPTR(FLong), 4
     CopyMemory mem_Default+80, VARPTR(FLong), 4
     CopyMemory mem_Default+84, VARPTR(FLong), 4
     CopyMemory mem_Default+88, VARPTR(FLong), 4
     count=0
     FLong=40
     rtnval=40
     Reg_EnumKey(count)
     WHILE (rtn<>ERROR_NO_MORE_ITEMS AND (rtn=ERROR_SUCCESS OR rtn=ERROR_MORE_DATA))
      stg$=VARPTR$(mem_Default)
      SHOWMESSAGE("SubKey Name: "+stg$)
      stg$=VARPTR$(mem_Default+40)
      SHOWMESSAGE("Class Name: "+stg$)
      CopyMemory VARPTR(FLong), mem_Default+80, 4
      SHOWMESSAGE(HEX$(FLong))
      CopyMemory VARPTR(FLong), mem_Default+84, 4
      SHOWMESSAGE(HEX$(FLong))
      INC count
      FLong=40
      rtnval=40
      Reg_EnumKey(count)
     WEND

     FLong=0
     CopyMemory mem_Default, VARPTR(FLong), 4
     CopyMemory mem_Default+4, VARPTR(FLong), 4
     CopyMemory mem_Default+8, VARPTR(FLong), 4
     CopyMemory mem_Default+40, VARPTR(FLong), 4
     CopyMemory mem_Default+44, VARPTR(FLong), 4
     CopyMemory mem_Default+48, VARPTR(FLong), 4
     CopyMemory mem_Default+80, VARPTR(FLong), 4
     CopyMemory mem_Default+84, VARPTR(FLong), 4
     CopyMemory mem_Default+88, VARPTR(FLong), 4
     count=0
     FLong=40
     rtnval=40
     Reg_EnumValue(count)
     WHILE (rtn<>ERROR_NO_MORE_ITEMS AND (rtn=ERROR_SUCCESS OR rtn=ERROR_MORE_DATA))
      stg$=VARPTR$(mem_Default)
      SHOWMESSAGE("Value Name: "+stg$)
      SHOWMESSAGE("Value Type: "+STR$(key_Type))
      IF key_Type=REG_BINARY THEN

      ELSEIF key_Type=REG_SZ THEN
       rtnval=40
       Reg_QueryValue("String")
       CopyMemory VARPTR(stgbuf$), mem_Default+40, rtnval
       stg$=MID$(stgbuf$, 0, rtnval)
       SHOWMESSAGE("String Value: "+stg$)
      ELSEIF key_Type=REG_DWORD THEN
       rtnval=4
       Reg_QueryValue("Dword")
       CopyMemory VARPTR(FDWord), mem_Default+40, 4
       SHOWMESSAGE("Value: "+HEX$(FDWord)+" "+STR$(rtnval))
      ELSEIF key_Type=REG_MULTI_SZ THEN
       rtnval=200
       Reg_QueryValue("StringArray")
       mem_Offset=0
       FOR FDWord=0 TO 9
        stgs$(FDWord)=VARPTR$(mem_Default+40+mem_Offset)
        mem_Offset=mem_Offset+LEN(stgs$(count))+2
        SHOWMESSAGE("String Array Value: "+stgs$(FDWord))
       NEXT
      END IF
      FLong=0
      FOR mem_Offset=0 TO 130 STEP 4
       CopyMemory mem_Default+mem_Offset, VARPTR(FLong), 4
      NEXT
      INC count
      FLong=40
      rtnval=40
      Reg_EnumValue(count)
     WEND

     Reg_CloseKey

' Delete a SubKey.
'Reg_DeleteKey("Software\\LanguageGUI")


     UnLock_DefaultMemory
     Free_DefaultMemory
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2023-1-28  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-07-18 20:44:36