【发布时间】:2015-04-16 22:43:50
【问题描述】:
我正在编写一个遇到问题的批处理脚本。
首先,它会检查管理员权限。
其次,它会检查系统上安装的 Microsoft Office 版本。
第三,它进入了不稳定的构建。
问题出在第三部分。我得到管理员的权利。我可以找到安装了什么版本的office,设置在%office-version%。但我无法在if 语句中正确检查 %office_version%。这是我的代码:
@echo Off
::----------------------------------------------
:: 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"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
::------------------------------------------------------------------------------
:: This part of the cod4e found what office is install on the computer
::-----------------------------------------------------------------------------
setlocal enableDelayedExpansion
for /f "tokens=2 delims==" %%O in ('ftype ^|findstr /r /I "\\OFFICE[0-9]*" 2^>nul') do (
set "verp=%%~O"
goto :end_for
)
:end_for
for %%P in (%verp%) do (
set "off_path=%%~dpP"
for %%V in ("!off_path:~0,-1!") do (
set "office_version=%%~nV"
goto :end_for2
)
)
:end_for2
echo %office_version%
Pause
::-----------------------------------------------------------------------------
:: That the var of %Offfice_Verson% then running the build in remove of that office software.
::-------------------------------------------------------------------------------
if %office_version%== office12 goto 2007
If %office_version%== office14 goto 2010
If %office_version%== office15 goto 2013
:2007
Echo Unstailling office 2007
cd "%ProgramFiles%\Common Files\microsoft shared\OFFICE12\Office Setup Controller"
Goto remove
:2010
Echo Unstailling office 2010
cd "%ProgramFiles%\Common Files\microsoft shared\OFFICE14\Office Setup Controller"
Goto remove
:2013
Echo Unstailling 2013
cd "%ProgramFiles%\Common Files\microsoft shared\OFFICE15\Office Setup Controller"
Goto Remove
:Remove
%homedrive%
SETUP.EXE
Echo Done!!!!!
Pause
Exit
因此,您可以发送给我的任何帮助都将是很大的帮助。谢谢。
【问题讨论】:
标签: batch-file command line