|
|
发表于 2012-11-16 17:08:36
|
显示全部楼层
for /f %%a in ('type %TEMP%\6c70ef5709acfbb79de47c27863d64eb') do (
set ofver=%%a
echo --------------Microsoft Office Word--------------------
reg query "%office%\%ofver:~-4%\Word\File MRU" 2>nul
echo --------------Microsoft Office Excel-------------------
reg query "%office%\%ofver:~-4%\Excel\File MRU" 2>nul
echo --------------Microsoft Office PowerPoint--------------
reg query "%office%\%ofver:~-4%\PowerPoint\File MRU" 2>nul)
因为每条命令在执行之前,变量就会被展开。以上几行都是属于一个 for 命令里的,也就是一条 for 命令。
在这条 for 命令之前并没有设置 ofver 变量,所以查不到结果。而当你第二次运行批处理时,因为第一次运行的 ofver 变量没有被清除,所以能够得到结果。
改成:
@echo off
setlocal enabledelayedexpansion
del %TEMP%\6c70ef5709acfbb79de47c27863d64eb >nul 2>nul
set office=HKEY_CURRENT_USER\Software\Microsoft\Office
(reg query %office% | find "11.0" || reg query %office% | find "12.0" || reg query %office% | find "14.0")>>%TEMP%\6c70ef5709acfbb79de47c27863d64eb
for /f %%a in ('type %TEMP%\6c70ef5709acfbb79de47c27863d64eb') do (
set ofver=%%a
echo --------------Microsoft Office Word--------------------
reg query "%office%\!ofver:~-4!\Word\File MRU" 2>nul
echo --------------Microsoft Office Excel-------------------
reg query "%office%\!ofver:~-4!\Excel\File MRU" 2>nul
echo --------------Microsoft Office PowerPoint--------------
reg query "%office%\!ofver:~-4!\PowerPoint\File MRU" 2>nul)
或者:- @echo off
- set office=HKEY_CURRENT_USER\Software\Microsoft\Office
- for /f "tokens=*" %%a in (' reg query %office% ^| findstr "1[124]\.0" ') do (
-
- echo --------------Microsoft Office Word--------------------
- reg query "%office%\%%~nxa\Word\File MRU"
-
- echo --------------Microsoft Office Excel-------------------
- reg query "%office%\%%~nxa\Excel\File MRU"
-
- echo --------------Microsoft Office PowerPoint--------------
- reg query "%office%\%%~nxa\PowerPoint\File MRU"
-
- ) 2>nul
- pause
复制代码 |
|