中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-07 01:53
48,040 topics / 350,125 posts / today 1 new / 48,252 members
DOS批处理 & 脚本技术(批处理室) » [Solved] Ask, how to judge whether a registry key value exists?
Printable Version  1,791 / 7
Floor1 Mekinery Posted 2007-12-24 14:17
初级用户 Posts 32 Credits 83
Determine whether there is an item with the value "Sysin" under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" in the registry, the key value is "Wins" (string), the type is "REG_SZ", and the value is "mondy".

1. If it exists, continue to execute (jump to the next instruction), if not, create a new one --- (exact match, including case)
For example, the item value is "Sysin" and cannot be "sysin" or other, the key value is "Wins" and cannot be "wins" or other, the value is "mondy" and cannot be "Mondy" or other

2. If it exists, continue to execute (jump to the next instruction), if not, create a new one --- (case-insensitive)

Urgently need to be solved, thank you!

[ Last edited by Mekinery on 2007-12-24 at 09:36 PM ]
Floor2 fastslz Posted 2007-12-24 15:54
铂金会员 Posts 2,315 Credits 5,493 From 上海
```batch
@echo off
reg query HKLM\SOFTWARE\Microsoft\Windows\Sysin|find "Sysin" ||call :No
reg query HKLM\SOFTWARE\Microsoft\Windows\Sysin|find "Wins" ||call :StillNo
reg query HKLM\SOFTWARE\Microsoft\Windows\Sysin|find "mondy" ||goto :NoMore

echo Continue here
pause

:No
reg add "HKLM\SOFTWARE\Microsoft\Windows\Sysin" /f /v "Wins" /t REG_SZ /d "mondy"
goto:eof

:StillNo
reg delete "HKLM\SOFTWARE\Microsoft\Windows\Sysin" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\Sysin" /f /v "Wins" /t REG_SZ /d "mondy"
goto:eof

:NoMore
echo Go find Gates ◎_◎
pause
```
Floor3 Mekinery Posted 2007-12-24 19:04
初级用户 Posts 32 Credits 83
fastslz is quite humorous. First of all, thank you again for fastslz, but it didn't achieve the result I wanted.
Maybe I didn't explain it clearly enough, then I'll simplify it a bit more:
Check if there is a string value named Wins with type REG_SZ and value mondy under the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Sysin".
Once again, confirm that there is a string, the name is "Wins", not "wins, WIns, ..", and the type is definitely "REG_SZ", not "REG_DWORD, REG_MULTI_SZ, REG_BINARY, REG_EXPAND_SZ, ...", and the data value of the key "Wins" is "mondy", not "Mondy, moNdy, ..."
String Type REG_SZ
Binary value Type REG_BINARY
DWORD Type REG_DWORD
...
It should need to search and judge, right?
If any item doesn't match, it should exit. If all match, then jump to the command segment to be executed.
This should be easier to understand...

[ Last edited by Mekinery on 2007-12-24 at 07:08 PM ]
Floor4 baomaboy Posted 2007-12-24 19:40
银牌会员 Posts 554 Credits 1,513
Complete Registry Operation Methods
This is a demonstration example of WMI operating the registry. After each dialog box pops up, you will find the operations of WMI on the registry by checking the corresponding location in the registry. After all operations are completed, the script will automatically restore all operations of this script on the registry.

① Create primary keys, create key values of various types.

② Read key values and analyze key value types.

③ Enumerate primary keys and key values.

④ Determine whether a key or key value exists.

⑤ Query the operation permissions of the registry key.

⑥ Monitor the registry root key, primary key, and key value, and prompt when changes are found.
Floor5 Mekinery Posted 2007-12-24 19:55
初级用户 Posts 32 Credits 83
Don't understand VBS. If the system disables VBS, then it's useless, right? Still, batch processing is better. It would be great if batch processing could be implemented. Still waiting~~~
Floor6 balinger Posted 2007-12-24 20:48
中级用户 Posts 115 Credits 356
@echo off
for /f "delims=" %%i in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows') do (if "%%i"=="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Sysin" goto 1)
goto no
:1
for /f "tokens=1,2,*" %%i in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Sysin') do (if "%%i%%j%%k"=="WinsREG_SZmondy" goto yes)
:no
echo no
goto end
:yes
echo yes
:end
pause
Floor7 fastslz Posted 2007-12-24 21:27
铂金会员 Posts 2,315 Credits 5,493 From 上海
Indeed, the second floor is just for demonstration. Actually, it's very simple. As long as there's one mismatch, it exits.



Or

Floor8 Mekinery Posted 2007-12-24 21:36
初级用户 Posts 32 Credits 83
Thanks everyone, learned new knowledge again, hehe~~
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023