ป้ายกำกับ: USB

Backup drivers โดย PowerShellBackup drivers โดย PowerShell

เหตุเกินจากที่ลง windows 11 ใหม่แบบ clean ๆ กับ USB แล้วดูเหมือนจะเรียบร้อยดีแต่ว่า มันกลับหา wifi ไม่เจอ เครื่องมันก็ไม่มีสาย lan (ตามแบบเครื่องใหม่ ๆ ที่เน้นบาง ยกง่าย) แล้วหยุดไป ต้องหาวิธีแก้ปัญหา เลยเขียน PowerShell ออกมาเพื่อ backup drivers ออกมาให้ใช้ backup ใส่ใน USB ไปเลย ก่อนที่จะล้างเครื่องใหม่อีกครั้ง
drivers_backup_utility.ps1

# =========================================================
# สคริปต์ตั้งค่าภาษาไทย + ปุ่ม Grave Accent (`) + Default User
# Version: 1.3 (Bulletproof Edition)
# รันในฐานะ Administrator เท่านั้น
# =========================================================

# 0. ตรวจสอบสิทธิ์ Administrator
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Write-Host "❌ กรุณารันสคริปต์นี้ในฐานะ Administrator" -ForegroundColor Red
    pause
    exit
}

Write-Host "🔍 กำลังตรวจสอบ Language Pack ภาษาไทย..." -ForegroundColor Cyan

# 1. ตรวจสอบและติดตั้ง Language Pack
$thaiPacks = Get-WindowsCapability -Online | Where-Object { $_.Name -like "Language.Basic~~~th-TH*" }
if ($thaiPacks) {
    $thaiPack = $thaiPacks | Where-Object { $_.State -eq "Installed" } | Select-Object -First 1
    if (-not $thaiPack) { $thaiPack = $thaiPacks | Select-Object -First 1 }

    if ($thaiPack.State -eq "Installed") {
        Write-Host "✅ Language Pack ไทยติดตั้งอยู่แล้ว" -ForegroundColor Green
    } else {
        try {
            Write-Host "⏳ กำลังติดตั้ง Language Pack ไทย (อาจใช้เวลานาน)..." -ForegroundColor Yellow
            Add-WindowsCapability -Online -Name $thaiPack.Name -ErrorAction Stop
            Write-Host "✅ ติดตั้ง Language Pack สำเร็จ" -ForegroundColor Green
        } catch {
            Write-Host "⚠️ ติดตั้ง Language Pack ไม่สำเร็จ แต่จะดำเนินการต่อ..." -ForegroundColor Yellow
        }
    }
}

# 2. ตั้งค่าสำหรับผู้ใช้ปัจจุบัน
Write-Host "`n⌨️ กำลังตั้งค่าลำดับภาษา (EN-US หลัก + TH)..." -ForegroundColor Cyan
$LangList = New-WinUserLanguageList en-US
$LangList.Add("th-TH")
Set-WinUserLanguageList -LanguageList $LangList -Force

# แก้ปัญหาแสดงผล `` (ใช้ Single Quote)
Write-Host '🔘 กำลังตั้งค่าปุ่ม ` สลับภาษาสำหรับ Current User (Modern + Legacy)...' -ForegroundColor Cyan

# Modern Toggle (Hotkey = 4)
$TogglePath = "HKCU:\Keyboard Layout\Toggle"
if (!(Test-Path $TogglePath)) { New-Item -Path $TogglePath -Force | Out-Null }
Set-ItemProperty -Path $TogglePath -Name "Hotkey" -Value "4" -Type String -Force

# Legacy Hotkey (สำหรับความเข้ากันได้สูง)
$LegacyPath = "HKCU:\Control Panel\Input Method\Hot Keys\00000000"
if (!(Test-Path $LegacyPath)) { New-Item -Path $LegacyPath -Force | Out-Null }
Set-ItemProperty -Path $LegacyPath -Name "Key Modifiers" -Value ([byte[]] @(0x02, 0xc0, 0x00, 0x00)) -Type Binary -Force
Set-ItemProperty -Path $LegacyPath -Name "Virtual Key" -Value ([byte[]] @(0xc0, 0x00, 0x00, 0x00)) -Type Binary -Force

Write-Host "✅ ตั้งค่าสำเร็จสำหรับผู้ใช้ปัจจุบัน" -ForegroundColor Green

# 3. คัดลอกไปยัง Welcome Screen + New User
Write-Host "`n📋 กำลังคัดลอกการตั้งค่าไปยัง Welcome Screen..." -ForegroundColor Cyan
try {
    Copy-UserInternationalSettingsToSystem -WelcomeScreen $true -NewUser $true -ErrorAction Stop
    Write-Host "✅ คัดลอกการตั้งค่าสำเร็จ" -ForegroundColor Green
} catch {
    Write-Host "⚠️ ไม่สามารถคัดลอกไปยัง Welcome Screen ได้ (ปกติใน Windows 11)" -ForegroundColor Yellow
}

# 4. ตั้งค่าสำหรับ Default User (NTUSER.DAT)
Write-Host "`n🔘 กำลังตั้งค่าปุ่ม ` สำหรับ Default User (ผู้ใช้ใหม่)..." -ForegroundColor Cyan

$DefaultUserPath = "C:\Users\Default\NTUSER.DAT"
$MountPath = "HKLM\DefaultUserTemp"

if (Test-Path $DefaultUserPath) {
    try {
        reg load $MountPath $DefaultUserPath | Out-Null

        # Modern Toggle สำหรับ Default User
        $DefTogglePath = "HKLM:\DefaultUserTemp\Keyboard Layout\Toggle"
        if (!(Test-Path $DefTogglePath)) { New-Item -Path $DefTogglePath -Force | Out-Null }
        Set-ItemProperty -Path $DefTogglePath -Name "Hotkey" -Value "4" -Type String -Force

        # Legacy Hotkey สำหรับ Default User
        $DefLegacyPath = "HKLM:\DefaultUserTemp\Control Panel\Input Method\Hot Keys\00000000"
        if (!(Test-Path $DefLegacyPath)) { New-Item -Path $DefLegacyPath -Force | Out-Null }
        Set-ItemProperty -Path $DefLegacyPath -Name "Key Modifiers" -Value ([byte[]] @(0x02, 0xc0, 0x00, 0x00)) -Type Binary -Force
        Set-ItemProperty -Path $DefLegacyPath -Name "Virtual Key" -Value ([byte[]] @(0xc0, 0x00, 0x00, 0x00)) -Type Binary -Force

        Write-Host "✅ ตั้งค่าปุ่ม ` สำหรับ Default User สำเร็จ" -ForegroundColor Green
    }
    catch {
        Write-Host "⚠️ เกิดข้อผิดพลาดในการตั้งค่า Default User: $($_.Exception.Message)" -ForegroundColor Red
    }
    finally {
        # Unload Registry อย่างปลอดภัย
        Set-Location C:\
        Start-Sleep -Milliseconds 800
        [gc]::Collect()
        [gc]::WaitForPendingFinalizers()

        $unloadRetry = 0
        while ($unloadRetry -lt 5) {
            reg unload $MountPath 2>$null | Out-Null
            if ($LASTEXITCODE -eq 0) { break }
            $unloadRetry++
            Start-Sleep -Seconds 1
        }
    }
} else {
    Write-Host "⚠️ ไม่พบไฟล์ NTUSER.DAT ของ Default User" -ForegroundColor Red
}

# สรุปผล
Write-Host "`n====================================================" -ForegroundColor Cyan
Write-Host "✅ ดำเนินการเสร็จสิ้นทั้งหมด! (Version 1.3)" -ForegroundColor Green
Write-Host "👉 แนะนำให้ Sign out หรือ Restart เครื่องเพื่อให้การเปลี่ยนแปลงมีผลเต็มที่" -ForegroundColor Yellow
Write-Host "====================================================" -ForegroundColor Cyan

pause

วิธีใช้

  1. สร้างไฟล์ drivers_backup_utility.ps1 โดยใช้ notepad แล้ว save as เป็น drivers_backup_utility.ps1 บน Desktop หรือจะใส่ใน USB เลยก็ได้
  2. ใส่เนื้อหาตามข้างบน
  3. ไปที่เมนูของ windows
  4. ช่องค้นหา พิมพ์ powershell
  5. พิมพ์ cd ตามด้วย folder ที่ save drivers_backup_utility.ps1 ไว้อย่าง
    cd /d %USERPROFILE%/Desktop
  6. ใช้โดยพิมพ์ ./drivers_backup_utility.ps1
  7. ทำตามขั้นตอนไปเรื่อย ๆ

อ่านเพิ่มเติม