I am writing a batch file, this batch file will be distributed to many computers in our company by a agent software, and run on them.
It will install some patches on target computer, and need five times restart. the batch file will register itself in HKLM\Software\Microsfot\Windows\CurrentVersion\Run
, the problem is all those computer have password, my batch file can only run after user login.
the whole process will take 1.5 hours, I don't want users to sit in front their computer and wait to input password.
Is there any way to temporarily clear user's password or auto login a user ?
here is my batch file:
@echo off
color 1a
mode con:cols=120 lines=50
setlocal enableextensions enabledelayedexpansion
rem 判断是否以管理员运行
fltmc 1>nul || (
echo 未用管理员运行!退出执行
exit
)
if "%PROCESSOR_ARCHITECTURE%"=="x86" (set ARCH=x86) else (set ARCH=x64)
for /f "tokens=4-8 delims=[.] " %%i in ('ver') do @(if %%i==Version (set verstr=%%j.%%k.%%l.%%m) else (set verstr=%%i.%%j.%%k.%%l))
for /f "tokens=1-5 delims=." %%i in ('echo %verstr%') do @(
set OSV=%%i.%%j
set BLD=%%k
set MIV=%%l
)
set tempdir=edgesetup
set logfile=edgesetup.log
set cdn=http://x.x.x.x/soft
if %OSV% neq 6.1 echo not windows 7 && exit
call :Resume
goto %current%
goto :eof
rem =================== step1 ===================
:one
mkdir C:\%tempdir%
reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /d %~dpnx0 /f >>c:\%logfile% 2>&1
echo two >%~dp0current.txt
call:installkb 3020369
call:installkb 3125574
call:installkb 4490628
shutdown -r -t 0
goto :eof
rem =================== step2 ===================
:two
echo three >%~dp0current.txt
call:installkb 4507437
shutdown -r -t 0
goto :eof
rem =================== step3 ===================
:three
echo four >%~dp0current.txt
call:installkb 2533623
call:installkb 2670838
call:installkb 2731771
call:installkb 2729094
call:installkb 2786081
call:installkb 2834140
shutdown -r -t 0
goto :eof
rem =================== step 4 ===================
:four
echo five >%~dp0current.txt
echo ---------------------------- 安装IE 11中... ----------------------------
echo ---------------------------- 安装IE 11 ---------------------------- >>c:\%logfile% 2>&1
powershell -c "(new-object System.Net.WebClient).DownloadFile('%cdn%/win7/%ARCH%/IE11-Windows6.1-%ARCH%-zh-cn.exe','C:\%tempdir%\IE11-Windows6.1-%ARCH%-zh-cn.exe')" >>c:\%logfile% 2>&1
C:\%tempdir%\IE11-Windows6.1-%ARCH%-zh-cn.exe /quiet /update-no /closeprograms /norestart >>c:\%logfile% 2>&1
if %ErrorLevel% equ 0 echo IE 11安装/升级成功
call:installkb 4511872
shutdown -r -t 0
goto :eof
rem =================== step 5 ===================
:five
reg delete HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /f
del %~dp0current.txt
echo ---------------------------- 安装OA控件中... ----------------------------
echo ---------------------------- 安装OA控件 ---------------------------- >>c:\%logfile% 2>&1
powershell -c "(new-object System.Net.WebClient).DownloadFile('%cdn%/EcologyPlugin.zip','C:\%tempdir%\EcologyPlugin.zip')" >>c:\%logfile% 2>&1
powershell -c "(new-object System.Net.WebClient).DownloadFile('%cdn%/unzip.exe','C:\%tempdir%\unzip.exe')" >>c:\%logfile% 2>&1
C:\%tempdir%\unzip.exe C:\%tempdir%\EcologyPlugin.zip -d C:\%tempdir% >>c:\%logfile% 2>&1
call C:\%tempdir%\EcologyPlugin\setup.bat >>c:\%logfile% 2>&1
if %ErrorLevel% equ 0 echo OA控件安装成功
echo ---------------------------- 安装edge浏览器中... ----------------------------
echo ---------------------------- 安装edge浏览器 ---------------------------- >>c:\%logfile% 2>&1
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\EdgeUpdate /v Allowsxs /t REG_DWORD /d 1 /f >>c:\%logfile% 2>&1
powershell -c "(new-object System.Net.WebClient).DownloadFile('%cdn%/MicrosoftEdgeEnterprise%ARCH%.msi','C:\%tempdir%\MicrosoftEdgeEnterprise%ARCH%.msi')" >>c:\%logfile% 2>&1
C:\%tempdir%\MicrosoftEdgeEnterprise%ARCH%.msi /quiet >>c:\%logfile% 2>&1
if %ErrorLevel% equ 0 echo Edge浏览器安装成功
echo ---------------------------- 设置组策略中... ----------------------------
echo ---------------------------- 设置组策略 ---------------------------- >>c:\%logfile% 2>&1
powershell -c "(new-object System.Net.WebClient).DownloadFile('%cdn%/LGPO.exe','C:\%tempdir%\LGPO.exe')" >>c:\%logfile% 2>&1
powershell -c "(new-object System.Net.WebClient).DownloadFile('%cdn%/gp.txt','C:\%tempdir%\gp.txt')" >>c:\%logfile% 2>&1
C:\%tempdir%\LGPO.exe /t C:\%tempdir%\gp.txt >>c:\%logfile% 2>&1
if %ErrorLevel% equ 0 echo 组策略设置成功
reg add HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce /v clear-edge-setup /d "cmd /C \"rd /Q /S C:\%tempdir%\"" /f >>c:\%logfile% 2>&1
shutdown -r -t 0
goto :eof
rem =================== 恢复执行 ===================
:resume
if exist %~dp0current.txt (
set /p current=<%~dp0current.txt
taskkill /F /IM explorer.exe
) else (
set current=one
)
goto :eof
:installkb
echo=
echo ------------------------ 安装补丁%~1中,请稍候...请勿关闭窗口 -------------------------
echo=
echo ---------------------------- 安装补丁%~1 ---------------------------- >>c:\%logfile% 2>&1
mkdir C:\%tempdir%\%~1
set KB=%~1
powershell -c "(new-object System.Net.WebClient).DownloadFile('%cdn%/win7/%ARCH%/windows6.1-kb%KB%-%ARCH%.msu','C:\%tempdir%\windows6.1-kb%KB%-%ARCH%.msu')" >>c:\%logfile% 2>&1
expand -F:* C:\%tempdir%\windows6.1-kb%KB%-%ARCH%.msu C:\%tempdir%\%KB% >>c:\%logfile% 2>&1
for %%i in (C:\%tempdir%\%~1\*KB%KB%*.cab) do (
echo %%i >>c:\%logfile% 2>&1
DISM.exe /Online /Add-Package /PackagePath:%%i /NoRestart >>c:\%logfile% 2>&1
systeminfo | findstr "KB%KB%"
if %ErrorLevel% equ 0 echo 补丁KB%KB%安装成功
)
exit /B 0
endlocal