China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 11:13
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Dear experts, please ask a question about judgment View 2,330 Replies 0
Original Poster Posted 2016-03-31 14:25 ·  中国 广东 深圳 电信
初级用户
Credits 60
Posts 20
Joined 2016-03-30 21:10
10-year member
UID 181540
Gender Male
Status Offline
You can modify the batch script as follows:

```batch
@echo off & setlocal enabledelayedexpansion
cd /d %~dp0
for /f "tokens=7* delims=\" %%i in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall') do (
reg export "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%%~i" reg.$ >nul
for /f "delims=" %%j in ('type reg.$ ^| findstr /i /c:"DisplayName" 2^>nul') do (
set DN=%%~j
set DN=!DN:"=!
)
for /f "delims=" %%k in ('type reg.$ ^| findstr /i /c:"InstallLocation" 2^>nul') do (
set IL=%%~k
set IL=!IL:"=!
set IL=!IL:\\=\!
)
if defined DisplayName (
if defined InstallLocation (
(echo ++++++++
echo 注册表值: %%~i
echo 软件名称: !DisplayName!
echo 安装路径: !InstallLocation!
echo,)>>1.txt
)
)
del reg.$
)
```

The main modification is to add conditional judgments. Only when both `DisplayName` and `InstallLocation` are defined will the relevant information be output to the text file, so as to achieve the effect of not writing the four lines corresponding to "Software Name: No information." into the text.
Forum Jump: