@echo off

cls

set SWNAME=Nexus Personal 5.8.12
       
TITLE %COMPUTERNAME% : Installazione %SWNAME%

if exist "C:\Program Files (x86)\Personal\bin64\personal64.exe" goto FConfig

echo.
echo ++++++++++++++++++++++++++++
echo Kill Process
echo ++++++++++++++++++++++++++++
tasklist | find "itcspsm.exe" && taskkill /F /IM "itcspsm.exe"
tasklist | find "itcspsrv.exe" && taskkill /F /IM "itcspsrv.exe"

echo.
echo ++++++++++++++++++++++++++++
echo Rimozione TrustWare CSP+
echo ++++++++++++++++++++++++++++
wmic product where "name like 'trustWare CSP%%'" call uninstall /nointeractive

if exist "C:\Windows\System32\itp11.cfg" del "C:\Windows\System32\itp11.cfg"
if exist "C:\Windows\SysWOW64\itp11.cfg" del "C:\Windows\SysWOW64\itp11.cfg"
if exist "C:\Windows\System32\personal.dll" del "C:\Windows\System32\personal.dll"
if exist "C:\idg_apl\IT Solution GmbH" rd /s /q "C:\idg_apl\IT Solution GmbH"

if not exist C:\Temp mkdir C:\Temp
if exist C:\Temp\Users.txt del C:\Temp\Users.txt

dir /B "C:\Users\" > C:\Temp\Users.txt

for /F %%G IN (C:\Temp\Users.txt) DO (
    if exist "C:\Users\%%G\AppData\Roaming\Personal" rd /S /Q "C:\Users\%%G\AppData\Roaming\Personal"
        ) > NUL 2>&1   

if exist C:\Temp\Users.txt del C:\Temp\Users.txt

echo.
echo Installazione Nexus Personal 5.8.12
msiexec /i "%~dp0personal-5.8.12_amd64_LSA_signed.msi" /qn /norestart /l*v C:\Temp\NexusPersonal-5.8.12.Log

:FConfig

echo.
echo ++++++++++++++++++++++++++++
echo Kill Process
echo ++++++++++++++++++++++++++++
tasklist | find "itcspsm.exe" && taskkill /F /IM "itcspsm.exe"
tasklist | find "itcspsrv.exe" && taskkill /F /IM "itcspsrv.exe"

echo.
echo ++++++++++++++++++++++++++++
echo Copia Personal.cfg
echo ++++++++++++++++++++++++++++
copy /Y "%~dp0AddOn\personal.cfg" "C:\Program Files (x86)\Personal\config\"

dir /B "C:\Users\" > C:\Temp\Users_.txt

for /F %%G IN (C:\Temp\Users_.txt) DO (
    if not exist "C:\Users\%%G\AppData\Roaming\Personal" mkdir "C:\Users\%%G\AppData\Roaming\Personal"
    if not exist "C:\Users\%%G\AppData\Roaming\Personal\config" mkdir "C:\Users\%%G\AppData\Roaming\Personal\config"
    copy /Y "%~dp0AddOn\personal.cfg" "C:\Users\%%G\AppData\Roaming\Personal\config\"
        ) > NUL 2>&1   

if exist C:\Temp\Users_.txt del C:\Temp\Users_.txt




