上一页 | 目录 | 下一页

D.5 如何读取 REG_MULTI_SZ 值

我写这个脚本来帮助 论坛这个主题里的 rpetges 。可以读取一个注册表 REG_MULTI_SZ 类型的键值并输出。在你测试这个脚本的时候不要忘了修改标有 "编辑这里!" 的地方。该注册表键必须为 REG_MULTI_SZ 类型,否则将显示错误。

OutFile "REG_MULTI_SZ Reader.exe"

Name "REG_MULTI_SZ Reader"

ShowInstDetails show

!define HKEY_CLASSES_ROOT        0x80000000
!define HKEY_CURRENT_USER        0x80000001
!define HKEY_LOCAL_MACHINE       0x80000002
!define HKEY_USERS               0x80000003
!define HKEY_PERFORMANCE_DATA    0x80000004
!define HKEY_PERFORMANCE_TEXT    0x80000050
!define HKEY_PERFORMANCE_NLSTEXT 0x80000060
!define HKEY_CURRENT_CONFIG      0x80000005
!define HKEY_DYN_DATA            0x80000006

!define KEY_QUERY_VALUE          0x0001
!define KEY_ENUMERATE_SUB_KEYS   0x0008

!define REG_NONE                 0
!define REG_SZ                   1
!define REG_EXPAND_SZ            2
!define REG_BINARY               3
!define REG_DWORD                4
!define REG_DWORD_LITTLE_ENDIAN  4
!define REG_DWORD_BIG_ENDIAN     5
!define REG_LINK                 6
!define REG_MULTI_SZ             7

!define RegOpenKeyEx     "Advapi32::RegOpenKeyExA(i, t, i, i, *i) i"
!define RegQueryValueEx  "Advapi32::RegQueryValueExA(i, t, i, *i, i, *i) i"
!define RegCloseKey      "Advapi32::RegCloseKeyA(i) i"

####### 编辑这里!

!define ROOT_KEY         ${HKEY_CURRENT_USER}
!define SUB_KEY          "Software\Joe Software"
!define VALUE            "Strings"

####### 停止编辑

Section "Read"
  StrCpy $0 ""
  StrCpy $1 ""
  StrCpy $2 ""
  StrCpy $3 ""
  System::Call "${RegOpenKeyEx}(${ROOT_KEY}, '${SUB_KEY}', \
    0, ${KEY_QUERY_VALUE}|${KEY_ENUMERATE_SUB_KEYS}, .r0) .r3"
 
  StrCmp $3 0 goon
    MessageBox MB_OK|MB_ICONSTOP "不能打开注册表键! ($3)"
    Goto done
goon:

  System::Call "${RegQueryValueEx}(r0, '${VALUE}', 0, .r1, 0, .r2) .r3"
 
  StrCmp $3 0 read
    MessageBox MB_OK|MB_ICONSTOP "不能查询注册表值! ($3)"
    Goto done
 
read:
 
  StrCmp $1 ${REG_MULTI_SZ} multisz
    MessageBox MB_OK|MB_ICONSTOP "注册表值不是 REG_MULTI_SZ! ($3)"
    Goto done
 
multisz:
 
  StrCmp $2 0 0 multiszalloc
    MessageBox MB_OK|MB_ICONSTOP "R注册表值为空! ($3)"
    Goto done
 
multiszalloc:

  System::Alloc $2
  Pop $1
 
  StrCmp $1 0 0 multiszget
    MessageBox MB_OK|MB_ICONSTOP "不能分配足够的内存! ($3)"
    Goto done
 
multiszget:
 
  System::Call "${RegQueryValueEx}(r0, '${VALUE}', 0, n, r1, r2) .r3"
 
  StrCmp $3 0 multiszprocess
    MessageBox MB_OK|MB_ICONSTOP "无法查询注册表值数据! ($3)"
    Goto done
 
multiszprocess:
 
  StrCpy $4 $1
 
  loop:
 
    System::Call "*$4(&t${NSIS_MAX_STRLEN} .r3)"
    StrCmp $3 "" done
    DetailPrint $3
    StrLen $5 $3
    IntOp $4 $4 + $5
    IntOp $4 $4 + 1 ;REG_MULTI_SZ 类型以一个 NULL 来分隔
    Goto loop
 
done:
 
  System::Free $1
 
  StrCmp $0 0 noClose
    System::Call "${RegCloseKey}(r0)"
 
noClose:

SectionEnd

written by KiCHiK

上一页 | 目录 | 下一页