通过GPO软件安装启动脚本

时间:2012-10-26 10:01:40

标签: batch-file cmd text-files gpo

我们希望通过GPO向客户端部署一些应用程序。安装包是.exe而不是.msi,因此我们无法通过正常的“计算机配置\策略\软件设置\软件安装”策略进行分发。

因此,我们考虑在“计算机配置\策略\ Windows设置\脚本\启动”下使用启动脚本。但是,该软件应该只安装一次而不是每次启动。因此,我们认为结果应记录在文本文件中,然后在启动时读取,如果文件存在,则不要安装。目前,我们非常基本的脚本看起来像这样:

IF EXIST "c:\vcredist_2010_x86.txt" GOTO END
IF EXIST "c:\vcredist_2010_x64.txt" GOTO END

:32-bit
if exist %SystemRoot%\SysWOW64 goto 64-bit
\\servername\sharename\C++Redist\2010\vcredist_2010_x86.exe /passive /norestart
echo "Microsoft Visual C++ 2010 Redistributable - x86" > "c:\vcredist_2010_x86.txt"
goto END

:64-bit
\\servername\sharename\C++Redist\2010\vcredist_2010_x64.exe /passive /norestart
echo "Microsoft Visual C++ 2010 Redistributable - x64" > "c:\vcredist_2010_x64.txt"

:END

工作正常,但我们想稍微改进一下。只有一个文本文件被写入(即c:\ software-dist.txt)并且每次安装相关的行(软件名称)被添加到该文件中会很好。在启动时,脚本应检查该行是否存在,如果是,则不安装,如果否则安装软件。

1 个答案:

答案 0 :(得分:3)

这样的东西?

:CheckOS
if exist %systemdrive%\"Program Files (x86)" (
set bit=x64
) else (
set bit=x86
)

:Check1
for /f "delims=" %%a in (C:\software-dist.txt) do (
if "%%a"=="softwarename" goto Check2
)

\\servername\sharename\vcredist_2010_%bit%.exe /passive /norestart
echo softwarename >>C:\software-dist.txt

:Check2
for /f "delims=" %%a in (C:\software-dist.txt) do (
if "%%a"=="Microsoft Visual 2008" goto :Check3
)

\\servername\sharename\C++Redist\vcredist_2008_%bit%.exe /passive /norestart
echo Microsoft Visual 2008 >>C:\software-dist.txt

:Check3
for /f "delims=" %%a in (C:\software-dist.txt) do (
if "%%a"==Microsoft Visual C++ 2005 Redistributable %bit% goto :Check4
)

\\servername\sharename\2005\vcredist_2005_%bit%.exe /passive /norestart
echo Microsoft Visual C++ 2005 Redistributable %bit% >>C:\software-dist.txt

:Check4
for /f "delims=" %%a in (C:\software-dist.txt) do (
if "%%a"==Microsoft .NET Framework 4 goto :END
)

\\servername\sharename\dotNet4.exe
echo Microsoft .NET Framework 4 >>C:\software-dist.txt

:END

这将检查单个txt文件以查看它是否包含具有软件名称的行。如果是,它会退出,如果不是,它会安装它并在完成后将其自身添加到列表中。