无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
查看: 6687|回复: 27
打印 上一主题 下一主题

[求助] wmic的环境在批处理里怎么退出?

[复制链接]
跳转到指定楼层
1#
发表于 2017-7-4 16:18:38 来自手机 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
调用它以后,怎么退出它的环境,却不影响批处理继续工作?
2#
 楼主| 发表于 2017-7-4 16:41:24 来自手机 | 只看该作者
echo.quit|wmic这种格式呢,有群友提示,我回去试试。
回复

使用道具 举报

3#
发表于 2017-7-4 17:43:12 来自手机 | 只看该作者
这玩意儿在批处理里面还用单独退出?不退出有影响?
回复

使用道具 举报

4#
 楼主| 发表于 2017-7-4 18:18:20 来自手机 | 只看该作者
嗯,后续的命令就会执行不了,比如字符串对比,就会提示获取字符串失败。
回复

使用道具 举报

5#
 楼主| 发表于 2017-7-5 09:16:37 来自手机 | 只看该作者
有办法吗?
回复

使用道具 举报

6#
发表于 2017-7-8 17:36:31 来自手机 | 只看该作者
批处理中,调用wmic 都是单一命令调用,自然退出。
回复

使用道具 举报

7#
发表于 2017-7-8 17:36:33 来自手机 | 只看该作者
批处理中,调用wmic 都是单一命令调用,自然退出。
回复

使用道具 举报

8#
 楼主| 发表于 2017-7-8 18:45:40 来自手机 | 只看该作者
但是后面的命令都执行失败了。
回复

使用道具 举报

9#
 楼主| 发表于 2017-7-8 18:54:59 | 只看该作者
  1. @echo off
  2. del list.log /q
  3. dir *-kb*.msu /b /o:n >a.txt
  4. wmic qfe get hotfixid >>1.tx
  5. tfor /f "delims=^- tokens=1,*" %%a in (1.txt) do (echo %%a>>2.txt)
  6. del 1.txt /q
  7. for /f "delims=^_ tokens=1,*" %%a in (2.txt) do (echo %%a>>b.txt)
  8. del 2.txt /q
  9. findstr /V /I /G:b.txt a.txt > c.txt && move /y c.txt list.log
  10. del *.txt
  11. for /f "eol=o eol=O " %%j in (list.log) do echo 正在安装补丁%%j && start /wait wusa %%j /quiet /norestart
复制代码


比如这个

点评

最近右臂摔了一下,骨裂了,回帖不便。 原因已经找到,WMIC输出的文本默认为unicode格式,而for默认是无法读取这种文本的,可以通过type 1.txt实现,或者将wmic结果用findstr处理一下再输出(建议只保留KB开头的  详情 回复 发表于 2017-7-15 20:18
回复

使用道具 举报

10#
发表于 2017-7-15 20:18:53 来自手机 | 只看该作者
窄口牛 发表于 2017-7-8 18:54
比如这个

最近右臂摔了一下,骨裂了,回帖不便。

原因已经找到,WMIC输出的文本默认为unicode格式,而for默认是无法读取这种文本的,可以通过type 1.txt实现,或者将wmic结果用findstr处理一下再输出(建议只保留KB开头的行),这样输出的文本默认ansi格式,for可以正常读取。
回复

使用道具 举报

11#
 楼主| 发表于 2017-7-15 22:11:13 来自手机 | 只看该作者
谢谢,好好养伤,愿早日康复。
回复

使用道具 举报

12#
 楼主| 发表于 2017-7-17 10:07:13 | 只看该作者
本帖最后由 窄口牛 于 2017-7-17 10:25 编辑
  1. @echo off
  2. del list.log /q
  3. dir *-kb*.exe /b /o:n >7.txt
  4. For %%a in (7.txt) Do Type %%a >a.txt
  5. del 7.txt /q
  6. wmic qfe get hotfixid >>8.txt
  7. For %%a in (8.txt) Do Type %%a >6.txt
  8. del 8.txt /q
  9. findstr /i "kb" 6.txt>>1.txt
  10. del 6.txt
  11. ::for /f "tokens=2" %%a in ('systeminfo^|findstr /i "kb"') do echo %%a>>1.txt
  12. for /f "delims=^- tokens=1,*" %%a in (1.txt) do (echo %%a>>2.txt)
  13. del 1.txt /q
  14. for /f "delims=^_ tokens=1,*" %%a in (2.txt) do (echo %%a>>b.txt)
  15. del 2.txt /q
  16. findstr /V /I /G:b.txt a.txt > c.txt && move /y c.txt list.log
  17. del *.txt
复制代码

又凑了几句进去前部分没问题了
筛选(findstr /V /I /G:b.txt a.txt > c.txt && move /y c.txt list.log)又失效了
回复

使用道具 举报

13#
发表于 2017-7-17 14:01:59 来自手机 | 只看该作者
窄口牛 发表于 2017-7-17 10:07
又凑了几句进去前部分没问题了
筛选(findstr /V /I /G:b.txt a.txt > c.txt && move /y c.txt list.log ...
  1. @echo off
  2. pushd %~dp0\
  3. del list.log /q 2>nul
  4. dir *-kb*.exe /b /o:n >a.txt
  5. for /f "tokens=1 delims=-_" %%a in ('wmic qfe get hotfixid ^| findstr /i "^KB"') do echo %%a>>b.txt
  6. findstr /V /I /G:b.txt a.txt > c.txt && move /y c.txt list.log
  7. del *.txt
复制代码
回复

使用道具 举报

14#
 楼主| 发表于 2017-7-17 15:25:42 | 只看该作者
最终测试这样可以顺利筛选
  1. @echo off
  2. pushd %~dp0\
  3. del list.log /q 2>nul
  4. dir *-kb*.exe /b /o:n >a.txt
  5. for /f %%a in ('wmic qfe get hotfixid ^| findstr /i "^KB"') do echo %%a>>1.txt
  6. ::for /f "tokens=2" %%a in ('systeminfo^|findstr /i "kb"') do echo %%a>>1.txt
  7. for /f "tokens=1 delims=-_" %%i in (1.txt) do echo %%i>>b.txt
  8. findstr /V /I /G:b.txt a.txt > c.txt && move /y c.txt list.log
  9. pause
  10. del *.txt
  11. for /f "eol=o eol=O " %%j in (list.log) do echo 正在安装补丁%%j && %%j /quiet /norestart
复制代码

不知道为什么简化后和我之前的就筛选失败
回复

使用道具 举报

15#
发表于 2017-7-17 18:07:10 来自手机 | 只看该作者
测试之前的筛选没有问题
回复

使用道具 举报

16#
 楼主| 发表于 2017-7-17 19:05:24 来自手机 | 只看该作者
原因不明,我这确实不行,无奈。

点评

回显开,在cmd中执行一下批处理排除一下错误  详情 回复 发表于 2017-7-17 21:56
回复

使用道具 举报

17#
发表于 2017-7-17 21:56:09 来自手机 | 只看该作者
窄口牛 发表于 2017-7-17 19:05
原因不明,我这确实不行,无奈。

回显开,在cmd中执行一下批处理排除一下错误
回复

使用道具 举报

18#
 楼主| 发表于 2017-7-18 07:48:40 | 只看该作者


无错误提示
回复

使用道具 举报

19#
发表于 2017-7-18 15:45:57 来自手机 | 只看该作者
怎么,没有生成list.log?
回复

使用道具 举报

20#
 楼主| 发表于 2017-7-18 16:08:06 来自手机 | 只看该作者
我测试的共13个补丁,正确应该是筛留2个补丁需要打,错误的筛留多与两个,因具体数字没记住,所以只用多于两个来描述。

点评

人工对比下a.txt b.txt,看多出来的有哪里不一样……  详情 回复 发表于 2017-7-18 16:19
回复

使用道具 举报

21#
发表于 2017-7-18 16:19:04 来自手机 | 只看该作者
窄口牛 发表于 2017-7-18 16:08
我测试的共13个补丁,正确应该是筛留2个补丁需要打,错误的筛留多与两个,因具体数字没记住,所以只用多于 ...

人工对比下a.txt b.txt,看多出来的有哪里不一样……
回复

使用道具 举报

22#
 楼主| 发表于 2017-7-18 16:51:37 来自手机 | 只看该作者
本帖最后由 窄口牛 于 2017-7-18 16:58 编辑

我测试的正确的就是两个。
a.txt
  1. IE8-WindowsXP-KB2964358-x86-custom-CHS.exe
  2. ie8-windowsxp-kb4018271-x86-custom-chs_4e41e3f3c9af0222e158d86aecf64fbfb0c9b48d.exe
  3. WindowsXP-KB2483618-x86-CHS.exe
  4. WindowsXP-KB2813345-x86-CHS.exe
  5. WindowsXP-KB2859537-x86-CHS.exe
  6. WindowsXP-KB4012583-x86-Custom-CHS.exe
  7. windowsxp-kb4012598-x86-custom-chs_dca9b5adddad778cfd4b7349ff54b51677f36775.exe
  8. WindowsXP-KB4018466-x86-Custom-CHS.exe
  9. WindowsXP-KB4019204-x86-Custom-CHS.exe
  10. WindowsXP-KB4022747-x86-Custom-CHS.exe
  11. WindowsXP-KB4024323-x86-Custom-CHS.exe
  12. WindowsXP-KB4024402-x86-Custom-CHS.exe
  13. WindowsXP-KB4025218-x86-Custom-CHS.exe
复制代码

正确筛选list.og
  1. WindowsXP-KB2483618-x86-CHS.exe
  2. WindowsXP-KB2813345-x86-CHS.exe
复制代码

错误筛选list.log
  1. WindowsXP-KB2483618-x86-CHS.exe
  2. WindowsXP-KB2813345-x86-CHS.exe
  3. WindowsXP-KB2859537-x86-CHS.exe
  4. WindowsXP-KB4012583-x86-Custom-CHS.exe
  5. windowsxp-kb4012598-x86-custom-chs_dca9b5adddad778cfd4b7349ff54b51677f36775.exe
  6. WindowsXP-KB4018466-x86-Custom-CHS.exe
  7. WindowsXP-KB4019204-x86-Custom-CHS.exe
  8. WindowsXP-KB4022747-x86-Custom-CHS.exe
  9. WindowsXP-KB4024323-x86-Custom-CHS.exe
  10. WindowsXP-KB4024402-x86-Custom-CHS.exe
  11. WindowsXP-KB4025218-x86-Custom-CHS.exe
复制代码

只筛掉了两个ie8的补丁
回复

使用道具 举报

23#
发表于 2017-7-18 17:33:24 来自手机 | 只看该作者
b.txt??
回复

使用道具 举报

24#
 楼主| 发表于 2017-7-18 18:05:01 | 只看该作者
b.txt

b.rar

2.83 KB, 下载次数: 3

点评

原因已经找到,wmic输出每个补丁名称后面有很多空格(除了有-_),文件名没有空格,所以只需将分隔符由“-_”改为“-_ ”即可,就是加了个空格  详情 回复 发表于 2017-7-18 18:32
回复

使用道具 举报

25#
发表于 2017-7-18 18:32:55 来自手机 | 只看该作者
窄口牛 发表于 2017-7-18 18:05
b.txt

原因已经找到,wmic输出每个补丁名称后面有很多空格(除了有-_),文件名没有空格,所以只需将分隔符由“-_”改为“-_ ”即可,就是加了个空格
回复

使用道具 举报

26#
 楼主| 发表于 2017-7-18 18:47:56 来自手机 | 只看该作者
完美!nt6不存在这个问题。大师好认真,硬硬的找到了问题所在,佩服!
回复

使用道具 举报

27#
发表于 2017-7-29 15:02:27 | 只看该作者
我自己专为WIN系统写的批处理,自动侦测WIN系统版本,并根据系统已有的补丁来判断还有多少补丁没有安装,最终自动安装系统没有的补丁程序。另外将此批处理与补丁放在同一目录内就可运行了。  横线下边的就是自动安装系统补丁批处理了。
=================================================================================================================================================


@echo off
title 系统补丁批量自动安装

color 1f

cls

PUSHD %~dp0
del /q /f *.txt

rem //判断WIN7、WIN8、WIN10系统并获取最高权限
ver|find /i "10.0." > NUL &&  goto UACwin10
ver|find /i "6.3." > NUL &&  goto UACwin8
ver|find /i "6.2." > NUL &&  goto UACwin8
ver|find /i "6.1." > NUL &&  goto UACwin7
ver|find /i "6.0." > NUL &&  goto UACwin7
ver|find /i "5.00"> NUL &&  goto fixpatch
ver|find /i "5.1"> NUL &&  goto fixpatch
ver|find /i "5.2"> NUL &&  goto fixpatch
IF EXIST %SystemRoot%\System32\PECMD.INI goto ErrSystem


:ErrSystem
cls
Echo.
Echo.
Echo  注意:经测试,本软件只适用于WINXP及其以上的Windows操作系统。
Echo  很遗憾,你的系统不符合本程序的要求。按回车键退出安装程序!!!
Pause >nul
Exit

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:fixpatch

IF /i not "%OS%."=="Windows_NT." goto ErrSystem

::判断系统版本并设置TheOS
ver|find /i "10.">nul &&SET Winver=nt6&& SET TheOS=Win10
ver|find /i "6.3">nul &&SET Winver=nt6&& SET TheOS=Win8.1
ver|find /i "6.2">nul &&SET Winver=nt6&& SET TheOS=Win8
ver|find /i "6.1">nul &&SET Winver=nt6&& SET TheOS=Win7
ver|find /i "6.0">nul &&SET Winver=nt6&& SET TheOS=Vista
ver|find /i "5.0">nul &&SET Winver=nt5&& SET TheOS=2000
ver|find /i "5.1">nul &&SET Winver=nt5&& SET TheOS=XP
ver|find /i "5.2">nul &&SET Winver=nt5&& SET TheOS=2003


cls

SET TP=%~dp0
SET TP=%TP:~0,-1%
cd /d %TP%

Echo.
@Echo  **************************************************
@Echo ║ [1] 运行全自动安装补丁(全部补丁都安装)     ║
@Echo ║                                              ║
@Echo ║ [2] 运行全自动安装补丁(系统已有的省略安装)  ║
@Echo ║                                              ║
@Echo ║ [3] 删除全部补丁                             ║
@Echo ║                                              ║
@Echo ║ [4] 查看目录内补丁                            ║
@Echo ║                                              ║
@Echo ║ [5] 退出本程序                                ║
@Echo  **************************************************
Echo.
Echo   您现在使用的是 %TheOS% 操作系统,请确保您拥有管理员权限
IF "%Winver%"=="nt6" Echo    并关闭了UAC和360等保护软件,否则安装可能失败!
Echo.

SET Choice=
SET /P Choice=   请选择要进行的操作 (1/2/3/4/5=退出) ,然后按回车:
Echo.
IF "%Choice%"=="" Goto fixpatch
IF Not "%Choice%"=="" SET Choice=%Choice:~0,1%
IF /I "%Choice%"=="1" Goto Start0
IF /I "%Choice%"=="2" Goto Start1
IF /I "%Choice%"=="3" Goto Del
IF /I "%Choice%"=="4" Goto Exp
IF /I "%Choice%"=="5" Goto Exit


rem //运行全自动安装补丁(全部补丁都安装)
:Start0
echo 请将此批处理与补丁放在同一目录内运行才能自动安装系统补丁
echo.

ver|find /i "5.00"> NUL &&  goto win_xp
ver|find /i "5.1"> NUL &&  goto win_xp
ver|find /i "5.2"> NUL &&  goto win_xp

rem //目录内补丁具体内容
dir /a /b *.msu > hotfix.txt

rem //显示目录内补丁总数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" hotfix.txt')do set/a patch1=%%a+0

echo.
echo.
@echo 总共要自动安装的系统补丁数:%patch1%
echo.


rem //生成安装批处理程序
echo.@echo off >install.cmd
echo.title win系统补丁自动安装 >>install.cmd


echo echo.总共要安装 %patch1% 个补丁 >>install.cmd
echo echo. >>install.cmd

for /l %%i in (1,1,%patch1%) do echo echo.Windows有%patch1%个补丁要安装,正在安装第%%i个补丁,请稍等......>>hotfixA.txt
echo echo. >>install.cmd
ver|find /i "6.2." > NUL &&  goto W8
ver|find /i "6.3." > NUL &&  goto W8


for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait wusa %%i /quiet /norestart>>hotfixB.txt


GOTO W7


:W8
for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait %%i /quiet /norestart>>hotfixB.txt



:W7
rem //合并成一个文件并生成批处理命令
setlocal enabledelayedexpansion
echo.
set "间隔行数=1"
echo.
for /f "delims=" %%a in (hotfixB.txt) do (
        set /a LineA+=1
        set "_!LineA!=%%a"
)

(for /f "delims=" %%a in (hotfixA.txt) do (
        echo,%%a
        set /a "m=(LineB+=1)%%间隔行数, x+=^!m, y=(x-1)%%LineA+1"
        if "!m!" == "0" for %%b in (!y!) do echo,!_%%b!
))>>install.cmd
echo.
echo echo.系统安装完成,将在40秒后关闭电脑。 >>install.cmd
echo.
echo Shutdown.exe -s -t 40 >>install.cmd
echo exit>>install.cmd

rem //删除hotfixA.txt
if exist hotfixA.txt del /q /f hotfixA.txt

rem //删除hotfixB.txt
if exist hotfixB.txt del /q /f hotfixB.txt

rem //删除
del /q /f hotfix*.txt

rem //准备运行install.cmd
if exist install.cmd start /wait install.cmd

rem //删除install.cmd
if exist install.cmd del /q /f install.cmd
echo.
echo 39秒后自动关闭电脑!
Shutdown.exe -s -t 39
exit






rem //运行全自动安装补丁(系统已有的省略安装)
:Start1
echo.
echo 请将此批处理与补丁放在同一目录内运行才能自动安装系统补丁...
echo.
ver|find /i "5.00"> NUL &&  goto win_xp1
ver|find /i "5.1"> NUL &&  goto win_xp1
ver|find /i "5.2"> NUL &&  goto win_xp1

color 0A
cls
rem //已经安装在系统上的补丁

for /f "tokens=2" %%a in ('systeminfo^|findstr /i "KB"') do (
echo %%a>>info.txt
)


rem //目录内所有补丁中还没安装上系统的补丁patch

rem //目录内补丁具体内容
dir /a /b *.msu > hotfix.txt

rem //显示目录内补丁总数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" hotfix.txt')do set/a patch1=%%a+0


copy /y hotfix.txt patch.txt >nul
for /f "delims=" %%a in (info.txt) do (
type patch.txt|find /i "%%a">nul&&(type patch.txt|find /v /i "%%a")>temp.txt
move /y temp.txt patch.txt >nul 2>nul
)
echo.
echo 目录内补丁总共有%patch1%个
Echo.

rem //显示目录内所有补丁中还没安装上系统的补丁的个数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" patch.txt')do set/a patch2=%%a+0

echo 目录内所有补丁中还没安装上系统的补丁有%patch2%个

if %patch2%==0 goto qqq

rem //生成安装批处理程序
echo.@echo off >install.cmd
echo.title win系统补丁自动安装 >>install.cmd
echo echo. >>install.cmd
echo echo.目录内总共有 %patch1% 个补丁,其中有 %patch2% 个补丁未被安装 >>install.cmd
echo echo. >>install.cmd
for /l %%i in (1,1,%patch2%) do echo echo.Windows有%patch2%个补丁将要安装,正在安装第%%i个补丁,请稍等......>>hotfixA.txt

ver|find /i "6.2." > NUL &&  goto W81
ver|find /i "6.3." > NUL &&  goto W81

for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait wusa %%i /quiet /norestart>>hotfixB.txt

GOTO W71


rem //win8和win8.1补丁安装方法
:W81
for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait %%i /quiet /norestart>>hotfixB.txt



:W71

rem //合并成一个文件并生成批处理命令
setlocal enabledelayedexpansion
echo.
set "间隔行数=1"
echo.
for /f "delims=" %%a in (hotfixB.txt) do (
        set /a LineA+=1
        set "_!LineA!=%%a"
)

(for /f "delims=" %%a in (hotfixA.txt) do (
        echo,%%a
        set /a "m=(LineB+=1)%%间隔行数, x+=^!m, y=(x-1)%%LineA+1"
        if "!m!" == "0" for %%b in (!y!) do echo,!_%%b!
))>>install.cmd
echo echo. >>install.cmd
echo echo.系统安装完成,将在40秒后关闭电脑。 >>install.cmd
echo.
echo Shutdown.exe -s -t 40 >>install.cmd
echo exit>>install.cmd
Echo.
Echo.
Pause

if exist info.txt del /q /f info*.txt
if exist hotfix.txt del /q /f hotfix*.txt
if exist patch.txt del /q /f *.txt


rem //准备运行install.cmd
if exist install.cmd start /wait install.cmd

rem //删除install.cmd
if exist install.cmd del /q /f install.cmd

exit



:qqq
echo.
echo.你的系统已经装过了目录内的补丁了!!!按任意键退出!
pause
exit




:win_xp
rem //winxp补丁(全部补丁都安装)
cls
echo.
echo.

rem //目录内补丁具体内容
dir /a /b *.exe > hotfix.txt


rem //显示目录内补丁总数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" hotfix.txt')do set/a patch1=%%a+0

echo.
echo.
@echo 总共要自动安装的系统补丁数:%patch1%
echo.
rem //生成安装批处理程序
echo.@echo off >install.cmd
echo.title win系统补丁自动安装 >>install.cmd


echo echo.总共要安装 %patch1% 个补丁 >>install.cmd
echo echo. >>install.cmd
for /l %%i in (1,1,%patch1%) do echo echo.Windows有%patch1%个补丁要安装,正在安装第%%i个补丁,请稍等......>>hotfixA.txt
echo echo. >>install.cmd
for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait %%i /passive /norestart /nobackup>>hotfixB.txt

rem //合并成一个文件并生成批处理命令
setlocal enabledelayedexpansion
echo.
set "间隔行数=1"
echo.
for /f "delims=" %%a in (hotfixB.txt) do (
        set /a LineA+=1
        set "_!LineA!=%%a"
)

(for /f "delims=" %%a in (hotfixA.txt) do (
        echo,%%a
        set /a "m=(LineB+=1)%%间隔行数, x+=^!m, y=(x-1)%%LineA+1"
        if "!m!" == "0" for %%b in (!y!) do echo,!_%%b!
))>>install.cmd

echo exit>>install.cmd


rem //删除hotfixA.txt
if exist hotfixA.txt del /q /f hotfixA.txt

rem //删除hotfixB.txt
if exist hotfixB.txt del /q /f hotfixB.txt

rem //删除
del /q /f hotfix*.txt

rem //准备运行install.cmd
if exist install.cmd start /wait install.cmd

rem //删除install.cmd
if exist install.cmd del /q /f install.cmd
echo.
echo 39秒后自动关闭电脑!
Shutdown.exe -s -t 39
exit




:win_xp1
rem //winxp补丁(系统未安装的补丁才装)
echo.
echo 请将此批处理与Windows补丁放在同一目录内运行才能自动安装系统补丁
echo.

rem ========目录内所有补丁中还没安装上系统的补丁==================

rem //目录内补丁具体内容
dir /a /b *.exe > hotfix.txt

rem //显示目录内补丁总数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" hotfix.txt')do set/a patch1=%%a+0

ver|find /i "5.00"> NUL &&  goto win_2k1
ver|find /i "5.1"> NUL &&  goto win_2k1

rem //已安装在系统上的补丁情况
for /f "tokens=2" %%a in ('systeminfo^|findstr /i "KB"') do (
echo %%a>>info.txt
)

copy /y hotfix.txt patch.txt >nul
for /f "delims=" %%a in (info.txt) do (
type patch.txt|find /i "%%a">nul&&(type patch.txt|find /v /i "%%a")>temp.txt
move /y temp.txt patch.txt >nul 2>nul
)

goto xp2k

:win_2k1
echo.
echo 正在检测已经安装的补丁
rem //从文件中取出一个补丁的名字,截取中间的补丁标号(如KB873339),到注册表查询这个是否已经安装了,没有就将其存放到patch.txt文件里
for /f "delims=- tokens=2" %%i in ('dir *-kb*.exe /b /on') do REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix\%%i" >nul || dir /b *%%i*.exe >>patch.txt && cls && echo 正在检测已经安装的补丁

goto xp2k
exit


:xp2k
echo.
echo 目录内补丁总共有%patch1%个
Echo.

rem //显示目录内所有补丁中还没安装上系统的补丁的个数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" patch.txt')do set/a patch2=%%a+0
echo.
echo 目录内所有补丁中还没安装上系统的补丁有%patch2%个
echo.
if %patch2%==0 goto qqq

rem //生成安装批处理程序
echo.@echo off >install.cmd
echo.title win系统补丁自动安装 >>install.cmd
echo.
echo echo.目录内总共有 %patch1% 个补丁,其中有 %patch2% 个补丁未被安装 >>install.cmd
echo echo. >>install.cmd
for /l %%i in (1,1,%patch2%) do echo echo.Windows有%patch2%个补丁将要安装,正在安装第%%i个补丁,请稍等......>>hotfixA.txt

for /f "tokens=1" %%i in (patch.txt) do echo.start /wait %%i /passive /norestart /nobackup>>hotfixB.txt

rem //合并成一个文件并生成批处理命令
setlocal enabledelayedexpansion
echo.
set "间隔行数=1"
echo.
for /f "delims=" %%a in (hotfixB.txt) do (
        set /a LineA+=1
        set "_!LineA!=%%a"
)

(for /f "delims=" %%a in (hotfixA.txt) do (
        echo,%%a
        set /a "m=(LineB+=1)%%间隔行数, x+=^!m, y=(x-1)%%LineA+1"
        if "!m!" == "0" for %%b in (!y!) do echo,!_%%b!
))>>install.cmd
echo.
echo echo.系统安装完成,将在40秒后关闭电脑。 >>install.cmd
echo.
echo Shutdown.exe -s -t 40 >>install.cmd
echo exit>>install.cmd
pause
Echo.
rem //准备运行install.cmd
if exist install.cmd start /wait install.cmd

rem //删除install.cmd
if exist install.cmd del /q /f install.cmd
Echo.
if exist info.txt del /q /f info*.txt
if exist hotfix.txt del /q /f hotfix*.txt
if exist patch.txt del /q /f *.txt
exit




:Exp
explorer %TP%
goto fixpatch
exit




:Del
echo 按任意键将删除目录内全部补丁文件,并退出程序!!!
pause
del /q /f *.exe
del /q /f *.msu
exit




:UACwin7
CLS
ECHO.
ECHO ================================
ECHO  WIN7获取批处理文件管理员权限
ECHO ================================

:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges(请求管理员权限)...
goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

"%temp%\getadmin.vbs"
exit /B

:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::     以下为需要运行的批处理文件代码     ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem 本行以下可修改为你需要的批处理命令

rem //去除WIN7-UAC小盾牌(重启电脑生效)
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /f /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /f /v EnableLUA /t REG_DWORD /d 0

taskkill /f /im explorer.exe
attrib -s -r -h "%userprofile%\AppData\Local\iconcache.db"
del "%userprofile%\AppData\Local\iconcache.db" /f /q
start explorer
goto fixpatch
exit



:UACwin8
CLS
ECHO.
ECHO ================================
ECHO  WIN8获取批处理文件管理员权限
ECHO ================================

:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges(请求管理员权限)...
goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

"%temp%\getadmin.vbs"
exit /B

:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::     以下为需要运行的批处理文件代码     ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem 本行以下可修改为你需要的批处理命令

rem //去除WIN8.1-UAC小盾牌
taskkill /f /im explorer.exe
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 77 /d "%systemroot%\system32\imageres.dll,197" /t reg_sz /f
del "%userprofile%\AppData\Local\iconcache.db" /f /q
taskkill /f /im explorer.exe
start %systemroot%\explorer

goto fixpatch
exit




:UACwin10

CLS
ECHO.
ECHO ================================
ECHO  WIN10获取批处理文件管理员权限
ECHO ================================
:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO.
ECHO ********************************
ECHO 请求 UAC 权限批准……
ECHO ********************************
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
exit /B

:gotPrivileges
setlocal & pushd .
cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::     以下为需要运行的批处理文件代码     ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem 本行以下可修改为你需要的批处理命令

REM //关闭WIN10用户账户控制(UAC)
rem reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "EnableLUA" /d 0 /t REG_DWORD /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "ConsentPromptBehaviorAdmin" /d 0 /t REG_DWORD /f


goto fixpatch

exit
回复

使用道具 举报

28#
 楼主| 发表于 2017-7-29 15:16:03 来自手机 | 只看该作者
不错,谢谢分享!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-4-20 07:02

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表