Files
setup-script/setupScriptInfo.ps1

206 lines
8.9 KiB
PowerShell

# Activate windows
irm https://massgrave.dev/get | iex
#Download temp files
$tmpPath = Join-Path $env:LOCALAPPDATA "Temp"
$filesToDownload = @(
@{
Url = "https://education.lego.com/_/downloads/EV3_Classroom_Windows_1.5.3_Global.msi"
FileName = "EV3_Classroom_Windows_1.5.3_Global.msi"
},
@{
Url = "https://cdn.discordapp.com/attachments/704760633379389533/1161288505390026772/simulation.zip"
FileName = "Simulation Domotique.zip"
},
@{
Url = "https://cdn.discordapp.com/attachments/704760633379389533/1161288504765059172/RobotProg.zip"
FileName = "RobotProg.zip"
}
)
foreach ($fileInfo in $filesToDownload) {
$filePath = Join-Path $tmpPath $fileInfo.FileName
if (-not (Test-Path -Path $filePath -PathType Leaf)) {
Invoke-WebRequest -Uri $fileInfo.Url -OutFile $filePath
}
}
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# Setup users
$username = "Eleve"
if (-not (Test-Path "C:\Users\$username")) {
Write-Host "User $username doesn't exist. Creating the user..."
New-LocalUser -Name $username -Description "New User Account" -NoPassword -PasswordNeverExpires $true -UserMayChangePassword $false
} else {
Write-Host "User $username already exists."
Set-LocalUser -Name $username -PasswordNeverExpires $true -UserMayChangePassword $false -Password ([securestring]::new())
}
$username = "Prof"
$SecurePassword = ConvertTo-SecureString -String "IPRprof2398" -AsPlainText -Force
if (-not (Test-Path "C:\Users\$username")) {
Write-Host "User $username doesn't exist. Creating the user..."
New-LocalUser -Name $username -Description "New User Account" -Password $SecurePassword -PasswordNeverExpires $true -UserMayChangePassword $false
} else {
Write-Host "User $username already exists."
Set-LocalUser -Name $username -PasswordNeverExpires $true -UserMayChangePassword $false -Password $SecurePassword
}
$username = "Admin"
$SecurePassword = ConvertTo-SecureString -String "Lprsnm4ehk26-" -AsPlainText -Force
if (-not (Test-Path "C:\Users\$username")) {
Write-Host "User $username doesn't exist. Creating the user..."
New-LocalUser -Name $username -Description "New User Account" -Password $SecurePassword -PasswordNeverExpires $true -UserMayChangePassword $false
} else {
Write-Host "User $username already exists."
Set-LocalUser -Name $username -PasswordNeverExpires $true -UserMayChangePassword $false -Password $SecurePassword
}
# Function to load a user's HKU registry hive
function UserReg {
param (
[string] $Username
)
$UserProfiles = Get-WmiObject Win32_UserProfile | Where-Object { $_.Special -eq $false }
$UserProfile = $UserProfiles | Where-Object { $_.LocalPath.EndsWith("\$Username") }
if ($UserProfile -ne $null) {
$UserSID = $UserProfile.SID
$HivePath = Join-Path -Path $UserProfile.LocalPath -ChildPath "NTUSER.DAT"
return $UserSID, "Registry::HKEY_USERS\$UserSID"
} else {
Write-Host "User profile for $Username not found."
return $null, $null
}
}
function SetRegistry {
param (
[string] $regpath,
[string] $regproperty
)
if( -not (Test-Path -Path $regpath -PathType Container) ) {
New-Item -Path $regpath -Force -ItemType Registry
New-ItemProperty -Path $regpath -Name $regproperty -Value 1 -PropertyType DWord
}
else {
$RegistryItem = Get-ItemProperty -Path $regpath
if ($RegistryItem.PSObject.Properties.Name -contains $regproperty) {
Set-ItemProperty -Path $regpath -Name $regproperty -Value 1
} else {
New-ItemProperty -Path $regpath -Name $regproperty -Value 1 -PropertyType DWord
}
}
}
$TargetUsername = "Eleve"
$UserSID, $UserHKUPath = UserReg -Username $TargetUsername
# Add restriction
if ($UserSID -ne $null -and $UserHKUPath -ne $null) {
# Restrict access to Settings
$ControlPanelKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
$ControlPanelValueName = "NoControlPanel"
SetRegistry -regpath $ControlPanelKeyPath -regproperty $ControlPanelValueName
# Disable access to regedit
$REGKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\System"
$REGValueName = "DisableRegistryTools"
SetRegistry -regpath $REGKeyPath -regproperty $REGValueName
# Restrict access to Command Prompt
$CMDKeyPath = "$UserHKUPath\Software\Policies\Microsoft\Windows\System"
$CMDValueName = "DisableCMD"
SetRegistry -regpath $CMDKeyPath -regproperty $CMDValueName
# Add entries to DisallowRun for cmd.exe and powershell.exe
$DisallowRunKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
$DisallowRunValueName = "DisallowRun"
SetRegistry -regpath $DisallowRunKeyPath -regproperty $DisallowRunValueName
Write-Host (Get-ItemProperty -Path "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun")
$DisallowRunPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun"
$applications = @("cmd.exe", "powershell.exe", "powershell_ise.exe")
Get-ItemProperty -Path $DisallowRunPath | ForEach-Object {
Remove-ItemProperty -Path $DisallowRunPath -Name $_.PSObject.Properties.Name -ErrorAction SilentlyContinue
}
foreach ($valueName in $applications) {
New-ItemProperty -Path $DisallowRunPath -Name $valueName -Value $valueName -PropertyType String
}
} else {
Write-Host "Unable to get the user's HKU registry."
}
# Installing needed apps
choco upgrade all -y
choco install dotnet -y
choco install vcredist-all -y
choco install firefox -y
choco install 7zip -y
choco install onlyoffice -y
choco install googleearthpro -y
choco install adobereader -y
choco install sublimetext4 -y
choco install vlc -y
choco install audacity -y
choco install scratch -y --install-arguments="/allusers" --force
choco install mblock -y
Write-Host 'Installing Simulation Domotique...'
Expand-Archive -Path (Join-Path $tmpPath "Simulation Domotique.zip") -DestinationPath $env:ProgramFiles -Force
if (Test-Path -Path $(Join-Path $env:ProgramFiles "simulation") -PathType Container) {
if (Test-Path -Path $(Join-Path $env:ProgramFiles "Simulation Domotique") -PathType Container) {
Remove-Item -Path $(Join-Path $env:ProgramFiles "Simulation Domotique") -Recurse -Force
}
Rename-Item -Path $(Join-Path $env:ProgramFiles "simulation") -NewName "Simulation Domotique"
}
$targetExePath = "C:\Program Files\Simulation Domotique\simulation.exe"
$shortcutPath = (Join-Path $env:PUBLIC "Desktop\Simulation Domotique.lnk")
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $targetExePath
$shortcut.IconLocation = $targetExePath
$shortcut.WorkingDirectory = (Get-Item $targetExePath).DirectoryName
$shortcut.Save()
choco install arduino -y --install-arguments="/allusers" --force
choco install ganttproject -y
$msiFilePath = Join-Path -Path $tmpPath -ChildPath "EV3_Classroom_Windows_1.5.3_Global.msi"
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$msiFilePath`" /qn" -Wait
Expand-Archive -Path (Join-Path $tmpPath RobotProg.zip) -DestinationPath $env:ProgramFiles -Force
$targetExePath = "C:\Program Files\RobotProg\RobotProg.exe"
$shortcutPath = (Join-Path $env:PUBLIC "Desktop\RobotProg.lnk")
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $targetExePath
$shortcut.IconLocation = $targetExePath
$shortcut.WorkingDirectory = (Get-Item $targetExePath).DirectoryName
$shortcut.Save()
# URL shortcut
Disable-WindowsOptionalFeature -online -NoRestart -FeatureName internet-explorer-optional-amd64
$wshShell = New-Object -ComObject "WScript.Shell"
$urlShortcut = $wshShell.CreateShortcut((Join-Path $env:PUBLIC "Desktop\Office 365.url"))
$urlShortcut.TargetPath = "https://office.com/"
$urlShortcut.Save()
$urlShortcut = $wshShell.CreateShortcut((Join-Path $env:PUBLIC "Desktop\Ecole Direct.url"))
$urlShortcut.TargetPath = "https://ecoledirecte.com/"
$urlShortcut.Save()
$urlShortcut = $wshShell.CreateShortcut((Join-Path $env:PUBLIC "Desktop\PIX.url"))
$urlShortcut.TargetPath = "https://pix.fr/"
$urlShortcut.Save()
$urlShortcut = $wshShell.CreateShortcut((Join-Path $env:PUBLIC "Desktop\Framindmap.url"))
$urlShortcut.TargetPath = "https://framindmap.org/"
$urlShortcut.Save()
# RDP
Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" -Value 0
Enable-NetFirewallRule -Group "@FirewallAPI.dll,-28752"
# Update Windows
Install-Module -Name PSWindowsUpdate -Force
Get-WindowsUpdate -ForceInstall
Install-WindowsUpdate -AcceptAll -AutoReboot