function addPathToFront ($addendum) { $regLocation = "Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment" $path = (Get-ItemProperty -Path $regLocation -Name PATH).path #delete if exist $path = ($path.Split(';') | Where-Object { $_ -ne "$addendum" }) -join ';' Set-ItemProperty -Path $regLocation -Name PATH -Value $path #add first $path = "$addendum;$path" Set-ItemProperty -Path $regLocation -Name PATH -Value $path refreshenv } [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::ssl3 #[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $chk = dir env: | ? { $_.Value -match 'Chocolatey' } $chk if(!$chk) { Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) choco upgrade chocolatey } $dir = "C:\ProgramData\EPT" if(!(Test-Path -Path $dir)){ New-Item -ItemType directory -Path $dir } $url = "https://ept.sgp1.digitaloceanspaces.com/download/program/openjdk13.13.0.102.nupkg" $keep = $dir + "\openjdk13.13.0.102.nupkg" Write-Output "Downloading openjdk ..." $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($url, $keep) choco install openjdk13 -s $dir -y --force if (Test-Path $keep) { Remove-Item $keep } $url = "https://ept.sgp1.digitaloceanspaces.com/download/program/codeblocks.20.03.nupkg" $keep = $dir + "\codeblocks.20.03.nupkg" Write-Output "Downloading codeblocks ..." $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($url, $keep) choco install codeblocks -s $dir -y --force if (Test-Path $keep) { Remove-Item $keep } refreshenv $path_java = (Get-Command java.exe).Path $path_java = $path_java.Substring(0,$path_java.Length - ("\java.exe").Length) addPathToFront ($path_java) $path_cpp = "" try { $path_cpp = (Get-Command cpp.exe).Path $path_cpp = $path_cpp.Substring(0,$path_cpp.Length - ("\cpp.exe").Length) } catch { Write-Output "Cannot found codeblock path. EPT's script will add default path to env." $path_cpp = "C:\Program Files (x86)\CodeBlocks\MinGW\bin"; } addPathToFront ($path_cpp) Write-Output "Path:" (Get-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment’ -Name PATH).Path #EPT_LAB $url = '' $windows64 = (([Array](Get-WmiObject -Class Win32_Processor | Select-Object AddressWidth))[0].AddressWidth -eq 64) if($windows64) { $url = "https://elearn.expert-programming-tutor.com/online_test/download/file_to_download/windows64/EPT_LAB_01.jar" } else { $url = "https://elearn.expert-programming-tutor.com/online_test/download/file_to_download/windows32/EPT_LAB_01.jar" } if (![string]::IsNullOrEmpty($url)) { Write-Output "Downloading EPT_LAB ..." # Download the EPT_LAB $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($url, $dir + "\EPT_LAB.jar") #create batch $DesktopPath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop) $batFile = $DesktopPath + "\ept_lab.Bat" $ScriptLine ="java -jar C:\ProgramData\EPT\EPT_LAB.jar" Set-Content -Path $BatFile -Value $ScriptLine -Encoding ASCII } Set-ExecutionPolicy Restricted Write-Output "------------------Finish EPT Installation---------------------"