使用批处理格式文件,实现软件的自动安装.把以下代码保存为批处理格式.bat,双击打开,自动获取管理员权限,实现自动打开安装软件exe并执行安装.
需要注意的:安装路径下必须要对应的安装文件,否则不会安装哦.
@echo off
title Auto Install
color 1F
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)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::搜狗输入法
echo 安装搜狗输入法
start E:\Software\softwaresetupfile\sogou_pinyin.exe /S
if %errorlevel%==0 (echo SougouInput – OK) else (echo SougouInput – error)
可以实现批量安装软件,当然开始安装的时候还是需要手动点击下一步,下一步的.