function InstallMsi { param ( [string] $app ) Write-Host "Installing $app..." $msiFilePath = Join-Path -Path $tmpPath -ChildPath $app Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$msiFilePath`" /qn" -Wait } function InstallExeSetup { param ( [string] $app, [string] $skipIf ) Write-Host "Installing $app..." if (-not (Test-Path -Path $skipIf -PathType Container)) { Start-Process -FilePath $(Join-Path $tmpPath $app) -ArgumentList "/allusers /s" -Wait } else { Write-Host "$app already installed." } } function InstallExe { param ( [string] $app ) $appName = [System.IO.Path]::GetFileNameWithoutExtension($app) Write-Host "Installing $appName..." $targetPath = Join-Path $env:ProgramFiles $appName if (-not (Test-Path -Path $targetPath -PathType Container)) { New-Item -Path $targetPath -ItemType Directory } Copy-Item -Path (Join-Path $tmpPath $app) -Destination $targetPath -Force CreateShortcut -exe (Join-Path $targetPath $app) -app $appName } function InstallZipSetup { param ( [string] $zip, [string] $exe, [bool] $createSubfolder = $false ) $zipName = [System.IO.Path]::GetFileNameWithoutExtension($zip) Write-Host "Installing $zipName..." $expPath = Join-Path $tmpPath if ($createSubfolder) { $expPath = Join-Path $expPath $zipName } Expand-Archive -Path (Join-Path $tmpPath $zip) -DestinationPath $expPath -Force Start-Process -FilePath $(Join-Path -Path $tmpPath -ChildPath (Join-Path -Path $zipName -ChildPath $exe)) -ArgumentList "/allusers /s" -Wait } function InstallZipMsi { param ( [string] $zip, [string] $msi ) $zipName = [System.IO.Path]::GetFileNameWithoutExtension($zip) Write-Host "Installing $zipName..." $msiFilePath = Join-Path $tmpPath $(Join-Path $zipName $msi) Expand-Archive -Path (Join-Path $tmpPath $zip) -DestinationPath $tmpPath -Force Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$msiFilePath`" /qb" -Wait } function InstallZip { param ( [string] $zip, [string] $exe, [string] $app, [bool] $createSubfolder = $false, [string] $skipIf = $false ) if ($skipIf -ne $false -and (Test-Path -Path $skipIf -PathType Container)) { Write-Host "$app already installed." } else { $zipName = [System.IO.Path]::GetFileNameWithoutExtension($zip) Write-Host "Installing $zipName..." $targetPath = $env:ProgramFiles if ($createSubfolder) { $subFolder = Join-Path $env:ProgramFiles $zipName if (-not (Test-Path -Path $subFolder -PathType Container)) { New-Item -Path $subFolder -ItemType Directory } $targetPath = $subFolder } if (Test-Path -Path (Join-Path $targetPath $app) -PathType Container) { Remove-Item -Path (Join-Path $targetPath $app) -Recurse -Force } Expand-Archive -Path (Join-Path $tmpPath $zip) -DestinationPath $targetPath -Force if (-not $zipName.Equals($app) -and (-not (Test-Path -Path (Join-Path $targetPath $app) -PathType Container))) { Start-Sleep -s 2 Move-Item -Path (Join-Path $env:ProgramFiles $zipName) -Destination (Join-Path $env:ProgramFiles $app) } CreateShortcut -exe $(Join-Path -Path $env:ProgramFiles -ChildPath (Join-Path -Path $app -ChildPath $exe)) -app $app } } function CreateShortcut { param ( [string] $exe, [string] $app ) $shell = New-Object -ComObject WScript.Shell $shortcut = $shell.CreateShortcut($(Join-Path $env:PUBLIC "Desktop\$app.lnk")) $shortcut.TargetPath = $exe $shortcut.IconLocation = $exe $shortcut.WorkingDirectory = (Get-Item $exe).DirectoryName $shortcut.Save() } function CreateURLShortcut { param ( [string] $ShortcutName, [string] $TargetUrl ) $wshShell = New-Object -ComObject "WScript.Shell" $shortcutPath = Join-Path $env:PUBLIC "Desktop\$ShortcutName.url" $urlShortcut = $wshShell.CreateShortcut($shortcutPath) $urlShortcut.TargetPath = $TargetUrl $urlShortcut.Save() } function EditShortcut { param ( [string] $ShortcutPath, [string] $TargetPath, [string] $Arguments ) $wshShell = New-Object -ComObject "WScript.Shell" $shortcut = $wshShell.CreateShortcut($ShortcutPath) $shortcut.TargetPath = $TargetPath $shortcut.Arguments = $Arguments $shortcut.Save() } function InstallApps { param ( [string] $Type ) switch ($Type) { "Labo" { InstallExeSetup -app "winstars_installer.exe" -skipIf "C:\Program Files\WinStars3" InstallZip -zip "Tectoglob3D-win32-ia32.zip" -exe "Tectoglob3D.exe" -app "Tectoglob3D" InstallZip -zip "Tectoglob_11_complet.zip" -exe "TectoGlob.exe" -app "TectoGlob" InstallZip -zip "Sismolog.zip" -exe "Sismolog.exe" -app "Sismolog" InstallExe -app "Respipoisson.exe" InstallMsi -app "Regressi.msi" if ((Test-Path 'C:\Users\Admin\AppData\Roaming\Microsoft\Start Menu\Programs\Regressi.lnk') -and -not (Test-Path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Regressi.lnk')) { Move-Item -Path 'C:\Users\Admin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Regressi.lnk' -Destination 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\' -Force } if ((Test-Path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\') -and -not (Test-Path 'C:\Users\Public\Desktop\Regressi.lnk')) { Copy-Item -Path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Regressi.lnk' -Destination 'C:\Users\Public\Desktop\' -Force } InstallZip -zip "regavi.zip" -exe "regavi.exe" -app "regavi" InstallExe -app "Radiochr.exe" InstallZip -zip "Phylogene-Lycee-2021.zip" -exe "Programmes\Phylo.exe" -app "Phylogene" InstallZip -zip "paleoterre_el32.zip" -exe "paleoTerre.exe" -app "PaleoTerre" InstallExeSetup -app "Eduanat2_Setup_2.0.0.exe" -skipIf "C:\Program Files (x86)\Eduanat2" InstallExe -app "Couvac.exe" InstallZipMsi -zip "ChemSketch.zip" -msi "script.msi" InstallZipMsi -zip "Anagene.zip" -msi "Anagene.msi" InstallZip -zip "EduPython.zip" -exe "EduPython.exe" -app "EduPython" -skipIf "C:\Program Files\EduPython" InstallZip -zip "rastop.zip" -exe "RasTop.exe" -app "RasTop" InstallExeSetup -app "SalsaJ_2_3.exe" -skipIf "C:\Program Files (x86)\SalsaJ" EditShortcut -ShortcutPath $(Join-Path $env:PUBLIC "Desktop\SalsaJ.lnk") -TargetPath "C:\Program Files (x86)\Java\jre-1.8\bin\javaw.exe" -Arguments "-jar -Dfile.encoding=UTF-8 `"$env:ProgramFiles (x86)\SalsaJ\SalsaJ.jar`"" InstallMsi -app "AtelierScientifiqueElevePhy_FR_8_1_7.msi" } "Info" { InstallMsi -app "EV3_Classroom_Windows_1.5.3_Global.msi" InstallZip -zip "simulation.zip" -exe "simulation.exe" -app "Simulation Domotique" InstallZip -zip "RobotProg.zip" -exe "RobotProg.exe" -app "RobotProg" InstallExeSetup -app "googlesketchupwen.exe" -skipIf "C:\Program Files (x86)\Google\Google SketchUp 8\" CreateURLShortcut -ShortcutName "Office 365" -TargetUrl "https://office.com/" CreateURLShortcut -ShortcutName "Ecole Direct" -TargetUrl "https://ecoledirecte.com/" CreateURLShortcut -ShortcutName "PIX" -TargetUrl "https://pix.fr/" CreateURLShortcut -ShortcutName "Framindmap" -TargetUrl "https://framindmap.org/" } "Laptop" { Write-Host "Nothing to install." } default { Write-Host "Invalid selection." } } }