132 lines
5.3 KiB
PowerShell
132 lines
5.3 KiB
PowerShell
# FinalizeSetup.ps1
|
|
# Wymaga uruchomienia z uprawnieniami Administratora
|
|
#Requires -RunAsAdministrator
|
|
|
|
Write-Host "==========================================" -ForegroundColor Cyan
|
|
Write-Host " KREATOR FINALIZACJI KONFIGURACJI" -ForegroundColor Cyan
|
|
Write-Host "==========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# ---------------------------------------------------------
|
|
# 1. Ukrywanie dysków (Modyfikacja Rejestru - NoDrives)
|
|
# ---------------------------------------------------------
|
|
$drivesToHide = Read-Host "Jakie dyski ukryć? (np. E F G, wciśnij Enter by pominąć)"
|
|
|
|
if (![string]::IsNullOrWhiteSpace($drivesToHide)) {
|
|
# Rozdzielamy ciąg po spacjach i wyliczamy maskę bitową
|
|
$letters = $drivesToHide -split '\s+'
|
|
$noDrivesValue = 0
|
|
|
|
foreach ($letter in $letters) {
|
|
$char = $letter.ToUpper()[0]
|
|
# Sprawdzamy, czy to litera od A do Z
|
|
if ($char -ge 65 -and $char -le 90) {
|
|
# Wzór: A=1, B=2, C=4, D=8, E=16 itd.
|
|
$bit = [math]::Pow(2, ([int]$char - 65))
|
|
$noDrivesValue += $bit
|
|
}
|
|
}
|
|
|
|
$regPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
|
|
if (!(Test-Path $regPath)) {
|
|
New-Item -Path $regPath -Force | Out-Null
|
|
}
|
|
|
|
Set-ItemProperty -Path $regPath -Name "NoDrives" -Value $noDrivesValue -Type DWord
|
|
Write-Host "[INFO] Ustawiono ukrywanie dysków (Wartość w rejestrze: $noDrivesValue)." -ForegroundColor Green
|
|
} else {
|
|
Write-Host "[INFO] Pominięto ukrywanie dysków." -ForegroundColor DarkGray
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# ---------------------------------------------------------
|
|
# 2. Dodawanie dysku na pulpit publiczny
|
|
# ---------------------------------------------------------
|
|
$shortcutDrive = Read-Host "Jaki dysk dodać na Pulpit publiczny? (np. E, wciśnij Enter by pominąć)"
|
|
|
|
if (![string]::IsNullOrWhiteSpace($shortcutDrive)) {
|
|
$shortcutDriveLetter = $shortcutDrive.ToUpper()[0]
|
|
$shortcutName = Read-Host "Jak nazwać ten skrót na pulpicie?"
|
|
|
|
# Pobieranie ścieżki do folderu "Pulpit publiczny" (C:\Users\Public\Desktop)
|
|
$publicDesktop = [Environment]::GetFolderPath('CommonDesktopDirectory')
|
|
$shortcutPath = Join-Path -Path $publicDesktop -ChildPath "$shortcutName.lnk"
|
|
|
|
# Wykorzystanie obiektu COM do utworzenia skrótu
|
|
$wshShell = New-Object -ComObject WScript.Shell
|
|
$shortcut = $wshShell.CreateShortcut($shortcutPath)
|
|
$shortcut.TargetPath = "$shortcutDriveLetter`:\"
|
|
$shortcut.Save()
|
|
|
|
Write-Host "[INFO] Utworzono publiczny skrót '$shortcutName' kierujący na $shortcutDriveLetter:\." -ForegroundColor Green
|
|
} else {
|
|
Write-Host "[INFO] Pominięto tworzenie skrótu." -ForegroundColor DarkGray
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# ---------------------------------------------------------
|
|
# 3. Połączenie z Wi-Fi (Tworzenie i import profilu XML)
|
|
# ---------------------------------------------------------
|
|
$connectWifi = Read-Host "Połączyć do Wi-Fi? (T/n)"
|
|
|
|
if ($connectWifi -match '^[Tt]$') {
|
|
$ssid = Read-Host "Podaj nazwę Wi-Fi"
|
|
$password = Read-Host "Podaj hasło do Wi-Fi"
|
|
|
|
# PowerShell wymaga utworzenia pliku XML, aby dodać sieć z hasłem bez GUI
|
|
$xmlProfile = @"
|
|
<?xml version="1.0"?>
|
|
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
|
|
<name>$ssid</name>
|
|
<SSIDConfig>
|
|
<SSID>
|
|
<name>$ssid</name>
|
|
</SSID>
|
|
</SSIDConfig>
|
|
<connectionType>ESS</connectionType>
|
|
<connectionMode>auto</connectionMode>
|
|
<MSM>
|
|
<security>
|
|
<authEncryption>
|
|
<authentication>WPA2PSK</authentication>
|
|
<encryption>AES</encryption>
|
|
<useOneX>false</useOneX>
|
|
</authEncryption>
|
|
<sharedKey>
|
|
<keyType>passPhrase</keyType>
|
|
<protected>false</protected>
|
|
<keyMaterial>$password</keyMaterial>
|
|
</sharedKey>
|
|
</security>
|
|
</MSM>
|
|
</WLANProfile>
|
|
"@
|
|
|
|
$tempXmlPath = Join-Path $env:TEMP "$ssid-profile.xml"
|
|
$xmlProfile | Out-File -FilePath $tempXmlPath -Encoding UTF8
|
|
|
|
Write-Host "[INFO] Dodawanie profilu sieci $ssid do systemu..." -NoNewline
|
|
$addResult = netsh wlan add profile filename="$tempXmlPath"
|
|
|
|
# Sprzątanie - usuwamy plik XML z jawnym hasłem
|
|
Remove-Item -Path $tempXmlPath -Force
|
|
|
|
if ($addResult -match "is added" -or $addResult -match "został dodany") {
|
|
Write-Host " GOTOWE" -ForegroundColor Green
|
|
Write-Host "[INFO] Próba połączenia z siecią $ssid..." -ForegroundColor Cyan
|
|
netsh wlan connect name="$ssid"
|
|
} else {
|
|
Write-Host " BŁĄD" -ForegroundColor Red
|
|
Write-Host " Odpowiedź systemu: $addResult" -ForegroundColor Yellow
|
|
}
|
|
} else {
|
|
Write-Host "[INFO] Pominięto konfigurację Wi-Fi." -ForegroundColor DarkGray
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "==========================================" -ForegroundColor Cyan
|
|
Write-Host " Konfiguracja zakończona!" -ForegroundColor Cyan
|
|
Write-Host "==========================================" -ForegroundColor Cyan
|
|
Write-Host "UWAGA: Ukrycie dysków zacznie działać po restarcie komputera (lub ponownym uruchomieniu procesu explorer.exe)." -ForegroundColor Yellow |