Registry是NSIS对注册表进行查找导入导出增改删操作的插件

/*
Registry是NSIS对注册表进行查找导入导出增改删操作的插件
registry支持对注册表进行查找,对键值是否存在进行判断,注册表读取,写入,创建,删除,删除空值键,复制,移动
registry可以将字符串转换成十六进制格式,也可以将十六进制串转成字符串.
*/
!AddIncludeDir "../Include"
!AddPluginDir "../Plugins"
Name "RegistryTest"
OutFile "RegistryTest.exe"
!include "Registry.nsh"
!include "Sections.nsh"
Var RADIOBUTTON
Page components
Page instfiles
Section "Basic registry functions" Basic
${registry::KeyExists} "HKEY_CURRENT_USERSOFTWARENSIS" $R0
MessageBox MB_OK "registry::KeyExists$n$n
Errorlevel: [$R0]"
${registry::Write} "HKEY_CURRENT_USERSOFTWARENSIS" "new" "%WINDIR%notepad.exe" "REG_EXPAND_SZ" $R0
MessageBox MB_OK "registry::Write$n$n
Errorlevel: [$R0]"
${registry::Read} "HKEY_CURRENT_USERSOFTWARENSIS" "new" $R0 $R1
MessageBox MB_OK 'registry::Read$n$n
$R0 "string" =[$R0]$n
$R1 "type" =[$R1]$n'
${registry::CreateKey} "HKEY_CURRENT_USERSOFTWARENSISnew1new2new3" $R0
MessageBox MB_OK "registry::CreateKey$n$n
Errorlevel: [$R0]"
${registry::CreateKey} "HKEY_CURRENT_USERSOFTWARENSISnew1new2new3" $R0
MessageBox MB_OK "registry::CreateKey$n$n
Errorlevel: [$R0]"
${registry::DeleteKeyEmpty} "HKEY_CURRENT_USERSOFTWARENSISnew1new2" $R0
MessageBox MB_OK "registry::DeleteEmptyKey$n$n
Errorlevel: [$R0]"
${registry::DeleteKeyEmpty} "HKEY_CURRENT_USERSOFTWARENSISnew1new2new3" $R0
MessageBox MB_OK "registry::DeleteEmptyKey$n$n
Errorlevel: [$R0]"
${registry::DeleteKey} "HKEY_CURRENT_USERSOFTWARENSISnew1" $R0
MessageBox MB_OK "registry::DeleteKey$n$n
Errorlevel: [$R0]"
${registry::DeleteValue} "HKEY_CURRENT_USERSOFTWARENSIS" "new" $R0
MessageBox MB_OK "registry::DeleteValue$n$n
Errorlevel: [$R0]"
${registry::CopyValue} "HKEY_CURRENT_USERSOFTWARENSIS" "MakeNSISWPlacement" "HKEY_CURRENT_USERSOFTWARENSISSymbols" "copied_MakeNSISWPlacement" $R0
MessageBox MB_OK "registry::CopyValue$n$n
Errorlevel: [$R0]"
${registry::MoveValue} "HKEY_CURRENT_USERSOFTWARENSISSymbols" "copied_MakeNSISWPlacement" "HKEY_CURRENT_USERSOFTWARENSIS" "moved_MakeNSISWPlacement" $R0
MessageBox MB_OK "registry::MoveValue$n$n
Errorlevel: [$R0]"
${registry::DeleteValue} "HKEY_CURRENT_USERSOFTWARENSIS" "moved_MakeNSISWPlacement" $R0
${registry::CopyKey} "HKEY_CURRENT_USERSOFTWARENSIS" "HKEY_CURRENT_USERSOFTWARE_NSIS" $R0
MessageBox MB_OK "registry::CopyKey$n$n
Errorlevel: [$R0]"
${registry::MoveKey} "HKEY_CURRENT_USERSOFTWARE_NSIS" "HKEY_CURRENT_USERSOFTWARENSIS_" $R0
MessageBox MB_OK "registry::MoveKey$n$n
Errorlevel: [$R0]"
${registry::DeleteKey} "HKEY_CURRENT_USERSOFTWARENSIS_" $R0
${registry::StrToHexA} "Some Value" $0
${registry::Write} "HKEY_CURRENT_USERSOFTWARENSIS" "new" "$0" "REG_BINARY" $R0
MessageBox MB_OK "registry::StrToHexA$n$n
Hex string: [$0]"
${registry::Read} "HKEY_CURRENT_USERSOFTWARENSIS" "new" $R0 $R1
${registry::HexToStrA} "$R0" $R1
MessageBox MB_OK "registry::HexToStrA$n$n
String: [$R1]"
${registry::DeleteValue} "HKEY_CURRENT_USERSOFTWARENSIS" "new" $R0
#Write extra string
StrCpy $0 0
StrCpy $1 0
IntOp $0 $0 + 1
StrCpy $1 '$1.$0'
StrLen $2 $1
IntCmp $2 1022 0 -3
${registry::Write} "HKEY_CURRENT_USERSOFTWARENSIS" "new" "$1" "REG_SZ" $R0
MessageBox MB_OK "registry::Write$n$n
Errorlevel: [$R0]"
${registry::WriteExtra} "HKEY_CURRENT_USERSOFTWARENSIS" "new" "----More text----" $R0
MessageBox MB_OK "registry::WriteExtra$n$n
Errorlevel: [$R0]"
#Read extra string
StrCpy $0 0
loop:
${registry::ReadExtra} "HKEY_CURRENT_USERSOFTWARENSIS" "new" "$0" $R0 $R1
IntOp $0 $0 + 1022 #if binary data then +511
MessageBox MB_YESNO 'Read next part?$n$n
registry::ReadExtra$n$n
$R0 "string" =[$R0]$n
$R1 "type" =[$R1]' IDYES loop
${registry::DeleteValue} "HKEY_CURRENT_USERSOFTWARENSIS" "new" $R0
${registry::Unload}
SectionEnd
Section /o "Search for value 'Content Type'" SearchValue
${registry::Open} "HKEY_LOCAL_MACHINE" "/K=0 /V=1 /S=0 /B=1 /N='Content Type'" $0
StrCmp $0 0 0 loop
MessageBox MB_OK "Error" IDOK close
loop:
${registry::Find} "$0" $1 $2 $3 $4
MessageBox MB_OKCANCEL '$1 "path" =[$1]$n
$2 "value" =[$2]$n
$3 "string" =[$3]$n
$4 "type" =[$4]$n
$n
Find next?' IDOK loop
close:
${registry::Close} "$0"
${registry::Unload}
SectionEnd
Section /o "Search and write founded in text file" SearchAndWriteInFile
GetTempFileName $R0
FileOpen $R1 $R0 w
FileWrite $R1 'HKEY_CURRENT_CONFIG$r$n$r$n'
${registry::Open} "HKEY_CURRENT_CONFIG" "/B=1" $0
StrCmp $0 0 0 loop
MessageBox MB_OK "Error" IDOK close
loop:
${registry::Find} "$0" $1 $2 $3 $4
StrCmp $4 '' close
StrCmp $4 'REG_KEY' 0 +3
FileWrite $R1 '$4:"$1$2"$r$n'
goto +2
FileWrite $R1 '$4:"$1" "$2"="$3"$r$n'
goto loop
close:
${registry::Close} "$0"
${registry::Unload}
FileClose $R1
Exec '"notepad.exe" "$R0"'
SectionEnd
### If nsx.dll not found then "Search with banner" example will not be compile ###
!system 'ECHO.>"%TEMP%Temp$$.nsh"'
!system 'IF EXIST "${NSISDIR}Pluginsnxs.dll" ECHO !define nxs_exist>>"%TEMP%Temp$$.nsh"'
!include "$%TEMP%Temp$$.nsh"
!system 'DEL "%TEMP%Temp$$.nsh"'
!ifdef nxs_exist
Section /o "Search with banner - 'NxS' plugin required" SearchWithBanner
HideWindow
nxs::Show /NOUNLOAD `$(^Name) Setup`
/top `Setup searching something$nPlease wait... If you can...`
/pos 78 /h 0 /can 1 /end
${registry::Open} "HKLMSystem" '/K=0 /V=1 /S=0 /N="Unexisted Name" /T=REG_DWORD /B=2' $0
StrCmp $0 0 0 loop
MessageBox MB_OK "Error" IDOK close
loop:
${registry::Find} "$0" $1 $2 $3 $4
StrCmp $4 '' close
StrCmp $4 'BANNER' 0 code
nxs::Update /NOUNLOAD /sub "$1" /end
nxs::HasUserAborted /NOUNLOAD
Pop $5
StrCmp $5 1 close loop
code:
;... code
goto loop
close:
${registry::Close} "$0"
${registry::Unload}
nxs::Destroy
BringToFront
SectionEnd
!endif
Section /o "Save to the file" SaveKey
${registry::SaveKey} "HKCUSOFTWARENSIS" "saved.reg" "/G=1 /D=2" $R0
${registry::Unload}
MessageBox MB_OK "registry::SaveKey$n$n
Errorlevel: [$R0]"
SectionEnd
Section /o "Restore from the file" RestoreKey
${registry::RestoreKey} "saved.reg" $R0
${registry::Unload}
MessageBox MB_OK "registry::RestoreKey$n$n
Errorlevel: [$R0]"
SectionEnd
Function .onInit
StrCpy $RADIOBUTTON ${Basic}
FunctionEnd
Function .onSelChange
!insertmacro StartRadioButtons $RADIOBUTTON
!insertmacro RadioButton ${Basic}
!insertmacro RadioButton ${SearchValue}
!insertmacro RadioButton ${SearchAndWriteInFile}
!ifdef nxs_exist
!insertmacro RadioButton ${SearchWithBanner}
!endif
!insertmacro RadioButton ${SaveKey}
!insertmacro RadioButton ${RestoreKey}
!insertmacro EndRadioButtons
FunctionEnd
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容