Software installation startup-script via GPO

Kerstin Fischer picture Kerstin Fischer · Oct 26, 2012 · Viewed 25.1k times · Source

We would like to deploy a few applications to clients via GPO. The install packages are .exe and not .msi, hence we are not able to distribute via the normal "Computer Configuration\Policies\Software Settings\Software Installation" policy.

Hence, we thought about using a startup script under "Computer Configuration\Policies\Windows Settings\Scripts\Startup". However, the software should only install once and not each startup. Hence, we thought that the results should be recorded in a text file, which is then read on startup and if the file exists, then don't install. At the moment our very basic script looks line this:

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

Works just fine, but we would like to refine it a little. Would be nice to have just 1 text file which is written to (i.e. c:\software-dist.txt) and per installation the relevant line (Software Name) be added to this file. On startup, the script should check to see if the line exists, if yes then don't install, if no then install the software.

Answer

Bali C picture Bali C · Oct 26, 2012

Something like this?

: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

That will check the single txt file to see if it contains a line with the name of the software. If it does, it exits, if not it installs it and adds itself into the list when it's finished.