标题: [文本处理] bat 其中一段代码怎么运行2次? [打印本页]
作者: hentai87 时间: 2020-6-4 15:10 标题: bat 其中一段代码怎么运行2次?
本帖最后由 hentai87 于 2020-6-4 15:22 编辑
不想直接复制一次,以后要是改的话要改2个地方,而且复制2次,会加长代码
顺便问下,怎么优化括号,很多for 和if 弄的括号很多很乱- @echo off
- cd /d %~dp0
- %1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit
- taskkill /f /im DismHost.exe
- taskkill /f /im dism.exe
- setlocal EnableDelayedExpansion
-
- ::-------------------第一次
- for /f "delims=:" %%a in ('findstr /n msmg设置 ..\set.txt') do set n=%%a
- for /f "skip=%n% delims=" %%b in (..\set.txt) do (
- for /f "tokens=1,2* delims=: " %%A in ('%%b\Bin\x64\DISM10\dism.exe /NoRestart /image:%%b\Mount\Install /Get-Capabilities') do (
-
- if "%%A %%B"=="Capability Identity" (
- set CapId=%%C
- ) else if "%%A"=="State" if "%%B"=="Installed" (
- cd. >list.txt
- echo !CapId!>>list.txt
-
- findstr /g:black_list.txt /v list.txt 2>nul
- if errorlevel 2 (
- for /f "delims=" %%i in (list.txt) do (
- %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
- )
- ) else (
- for /f "delims=" %%i in ('findstr /g:black_list.txt /v list.txt 2^>nul') do (
- %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
- )
- ))))
-
- ::-------------------第二次
-
- endlocal
- pause
- exit /b
复制代码
作者: went 时间: 2020-6-4 16:10
set a=0
:run
...
set /a a+=1
if %a% lss 2 goto :run
作者: went 时间: 2020-6-4 16:36
你这括号太乱了,我尽力了
注意缩进和对齐,多换几行也无所谓,主要是要看的清楚- @echo off
- cd /d %~dp0
- %1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit
- taskkill /f /im DismHost.exe
- taskkill /f /im dism.exe
- setlocal EnableDelayedExpansion
-
- set a=0
- :run
- for /f "delims=:" %%a in ('findstr /n msmg设置 ..\set.txt') do set n=%%a
- for /f "skip=%n% delims=" %%b in (..\set.txt) do (
- for /f "tokens=1,2* delims=: " %%A in ('%%b\Bin\x64\DISM10\dism.exe /NoRestart /image:%%b\Mount\Install /Get-Capabilities') do (
- if "%%A %%B"=="Capability Identity" (
- set CapId=%%C
- ) else if "%%A"=="State" if "%%B"=="Installed" (
- cd. >list.txt
- echo !CapId!>>list.txt
- findstr /g:black_list.txt /v list.txt 2>nul
- if errorlevel 2 (
- for /f "delims=" %%i in (list.txt) do (
- %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
- )
- ) else (
- for /f "delims=" %%i in ('findstr /g:black_list.txt /v list.txt 2^>nul') do (
- %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
- )
- )
- )
- )
- )
- set /a a+=1
- if %a% lss 2 goto :run
- endlocal
- pause
- exit /b
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |