比如我用REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\测试
得出以下结果
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\测试
Inno Setup: Setup Version REG_SZ 5.3.10.ee2 (a)
Inno Setup: App Path REG_SZ C:\DIY
InstallLocation REG_SZ "C:\DIY\LOG"
我想将结果中的名称和值都准确的读取出来
但是名称中有空格,值中也有空格和引号
下面是我写的部分代码
当值中没有引号或者其他特殊符号的时候是可以读取的
有引号的时候就会出错,怎么解决这个问题呢- :ReadRegValue
- ::St WinXP、Win7注册表读取(20111016)
- ::IE版本
- CALL :ReadRegValueName "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer" "Version"
- ::文件夹路径
- CALL :ReadRegValueName "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
- CALL :ReadRegValueName "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
- GOTO :EOF
-
- :ReadRegValueName
- IF "%~1"=="" (GOTO :EOF) ELSE (IF "%~2"=="" (SET KeyName="%~1") ELSE (SET KeyName="%~1" /v "%~2"))
- ::WinXP skip=4,Win7 skip=2
- FOR /F "skip=2 tokens=*" %%i In ('reg query %KeyName%') Do (CALL :SeparationRegValue "%%i")
- GOTO :EOF
-
- :SeparationRegValue
- IF "%~1"=="" GOTO :EOF
- SET RegValue=Initial&SET RegValueName=Initial&SET RegData=Initial
- SET RegValue=%~1
- IF "%RegValue%"=="Initial" GOTO :EOF
-
- SET "RegValue=%RegValue:REG_SZ=∷%"
- SET "RegValue=%RegValue:REG_MULTI_SZ=∷%"
- SET "RegValue=%RegValue:REG_DWORD_BIG_ENDIAN=∷%"
- SET "RegValue=%RegValue:REG_DWORD=∷%"
- SET "RegValue=%RegValue:REG_BINARY=∷%"
- SET "RegValue=%RegValue:REG_DWORD_LITTLE_ENDIAN=∷%"
- SET "RegValue=%RegValue:REG_NONE=∷%"
- SET "RegValue=%RegValue:REG_EXPAND_SZ=∷%"
- FOR /F "tokens=1,2* delims=∷" %%i In ("%RegValue%") Do (SET RegValueName=%%i&SET RegData=%%j)
- IF "%RegData%"=="" GOTO :EOF
- :DelSpace
- ::WinXP Reg空格(TAB)
- IF "%RegValueName:~-1%"==" " (SET RegValueName=%RegValueName:~0,-1%&GOTO DelSpace)
- IF "%RegData:~,1%"==" " (SET RegData=%RegData:~1%&GOTO DelSpace)
- ::Win7 Reg空格
- IF "%RegValueName:~-1%"==" " (SET RegValueName=%RegValueName:~0,-1%&GOTO DelSpace)
- IF "%RegData:~,1%"==" " (SET RegData=%RegData:~1%&GOTO DelSpace)
-
- SET %RegValueName%=%RegData%
- @echo ----------------------------------------------
- @echo %RegValueName%=%RegData%
- GOTO :EOF
- ::----------------------------------------------
复制代码
|