修改电脑信息及电脑显卡运行内存等信息

1: 新建文件 CpuNameChanger.ps1

bash 复制代码
param(
    [switch]$Startup,
    [switch]$Restore
)

# ============================================================
# 配置
# ============================================================

# 修改成你希望显示的 CPU 名称
$CustomCpuName = "13th Gen Intel(R) Core(TM) i5-13400 CPU@3.20GHz"

# 开机任务名称
$TaskName = "Windows CPU Name Changer"

# 程序目录
$InstallDir = "C:\ProgramData\CpuNameChanger"

# 本脚本安装后的固定位置
$ScriptPath = "$InstallDir\CpuNameChanger.ps1"

# 原始 CPU 名称备份
$BackupFile = "$InstallDir\CpuNameBackup.txt"

# CPU 注册表
$CpuRegistryPath = "HKLM:\HARDWARE\DESCRIPTION\System\CentralProcessor"


# ============================================================
# 检查管理员权限
# ============================================================

function Test-Administrator {

    $identity = [Security.Principal.WindowsIdentity]::GetCurrent()

    $principal = New-Object Security.Principal.WindowsPrincipal($identity)

    return $principal.IsInRole(
        [Security.Principal.WindowsBuiltInRole]::Administrator
    )
}


# ============================================================
# 创建程序目录
# ============================================================

function Initialize-Directory {

    if (!(Test-Path $InstallDir)) {

        New-Item `
            -Path $InstallDir `
            -ItemType Directory `
            -Force | Out-Null

        Write-Host "已创建目录:" -ForegroundColor Green
        Write-Host $InstallDir
    }
}


# ============================================================
# 获取当前 CPU 名称
# ============================================================

function Get-CurrentCpuName {

    $Path = "$CpuRegistryPath\0"

    if (!(Test-Path $Path)) {
        return $null
    }

    $Property = Get-ItemProperty `
        -Path $Path `
        -Name "ProcessorNameString" `
        -ErrorAction SilentlyContinue

    if ($null -ne $Property) {
        return $Property.ProcessorNameString
    }

    return $null
}


# ============================================================
# 备份原始 CPU 名称
# ============================================================

function Backup-CpuName {

    # 已经备份过就不再备份
    if (Test-Path $BackupFile) {

        Write-Host ""
        Write-Host "检测到已有 CPU 名称备份,跳过备份。" `
            -ForegroundColor Gray

        return
    }

    $OriginalName = Get-CurrentCpuName

    if ([string]::IsNullOrWhiteSpace($OriginalName)) {

        Write-Host ""
        Write-Host "无法获取原始 CPU 名称。" `
            -ForegroundColor Red

        return
    }

    # 确保目录存在
    Initialize-Directory

    $OriginalName |
        Out-File `
            -FilePath $BackupFile `
            -Encoding UTF8 `
            -Force

    Write-Host ""
    Write-Host "原始 CPU 名称已备份:" `
        -ForegroundColor Yellow

    Write-Host $OriginalName `
        -ForegroundColor Yellow
}


# ============================================================
# 修改 CPU 名称
# ============================================================

function Set-CpuName {

    if (!(Test-Path $CpuRegistryPath)) {

        Write-Host ""
        Write-Host "找不到 CPU 注册表路径:" `
            -ForegroundColor Red

        Write-Host $CpuRegistryPath

        return
    }

    # 获取所有 CPU
    $CpuKeys = Get-ChildItem $CpuRegistryPath

    if ($null -eq $CpuKeys) {

        Write-Host "没有找到 CPU 核心信息。" `
            -ForegroundColor Red

        return
    }

    foreach ($CpuKey in $CpuKeys) {

        $Current = Get-ItemProperty `
            -Path $CpuKey.PSPath `
            -Name "ProcessorNameString" `
            -ErrorAction SilentlyContinue

        if ($null -eq $Current) {
            continue
        }

        Set-ItemProperty `
            -Path $CpuKey.PSPath `
            -Name "ProcessorNameString" `
            -Value $CustomCpuName `
            -Force

        Write-Host "CPU $($CpuKey.PSChildName) 修改成功:" `
            -ForegroundColor Green

        Write-Host "    $CustomCpuName"
    }
}


# ============================================================
# 创建开机自动执行任务
# ============================================================

function Install-StartupTask {

    Initialize-Directory

    # 当前脚本路径
    $CurrentScript = $PSCommandPath

    if ([string]::IsNullOrWhiteSpace($CurrentScript)) {

        Write-Host ""
        Write-Host "无法获取当前脚本路径。" `
            -ForegroundColor Red

        return
    }

    # 如果当前脚本不是安装目录中的脚本
    if ($CurrentScript -ne $ScriptPath) {

        Copy-Item `
            -Path $CurrentScript `
            -Destination $ScriptPath `
            -Force

        Write-Host ""
        Write-Host "脚本已安装到:" `
            -ForegroundColor Green

        Write-Host $ScriptPath
    }

    # PowerShell 路径
    $PowerShell = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"

    # 删除旧任务
    schtasks.exe /Delete `
        /TN "$TaskName" `
        /F 2>$null | Out-Null

    # 创建开机任务
    schtasks.exe /Create `
        /TN "$TaskName" `
        /TR "`"$PowerShell`" -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$ScriptPath`" -Startup" `
        /SC ONSTART `
        /RU SYSTEM `
        /RL HIGHEST `
        /F | Out-Null

    if ($LASTEXITCODE -eq 0) {

        Write-Host ""
        Write-Host "开机自动修改任务创建成功。" `
            -ForegroundColor Green

        Write-Host ""
        Write-Host "任务名称:" -ForegroundColor Gray
        Write-Host $TaskName

        Write-Host ""
        Write-Host "运行账户:SYSTEM" -ForegroundColor Gray
        Write-Host "触发方式:Windows 开机" -ForegroundColor Gray
    }
    else {

        Write-Host ""
        Write-Host "开机任务创建失败。" `
            -ForegroundColor Red
    }
}


# ============================================================
# 删除开机任务
# ============================================================

function Remove-StartupTask {

    schtasks.exe /Delete `
        /TN "$TaskName" `
        /F 2>$null | Out-Null

    Write-Host ""
    Write-Host "开机自动修改任务已删除。" `
        -ForegroundColor Yellow
}


# ============================================================
# 恢复原始 CPU 名称
# ============================================================

function Restore-CpuName {

    Write-Host ""
    Write-Host "============================================"
    Write-Host "        恢复原始 CPU 名称"
    Write-Host "============================================"

    if (!(Test-Path $BackupFile)) {

        Write-Host ""
        Write-Host "没有找到 CPU 名称备份文件:" `
            -ForegroundColor Red

        Write-Host $BackupFile

        return
    }

    $OriginalName =
        Get-Content $BackupFile -Encoding UTF8 |
        Select-Object -First 1

    if ([string]::IsNullOrWhiteSpace($OriginalName)) {

        Write-Host "备份文件为空。" `
            -ForegroundColor Red

        return
    }

    Write-Host ""
    Write-Host "准备恢复:" -ForegroundColor Yellow
    Write-Host $OriginalName -ForegroundColor Green

    $CpuKeys = Get-ChildItem $CpuRegistryPath

    foreach ($CpuKey in $CpuKeys) {

        $Current = Get-ItemProperty `
            -Path $CpuKey.PSPath `
            -Name "ProcessorNameString" `
            -ErrorAction SilentlyContinue

        if ($null -eq $Current) {
            continue
        }

        Set-ItemProperty `
            -Path $CpuKey.PSPath `
            -Name "ProcessorNameString" `
            -Value $OriginalName `
            -Force

        Write-Host "CPU $($CpuKey.PSChildName) 已恢复。" `
            -ForegroundColor Green
    }

    # 删除开机任务
    Remove-StartupTask

    Write-Host ""
    Write-Host "CPU 原始名称恢复完成。" `
        -ForegroundColor Green
}


# ============================================================
# 开机启动模式
# ============================================================

if ($Startup) {

    # 开机执行时不备份
    # 直接设置名称
    Set-CpuName

    exit
}


# ============================================================
# 恢复模式
# ============================================================

if ($Restore) {

    if (!(Test-Administrator)) {

        Write-Host ""
        Write-Host "恢复操作需要管理员权限。" `
            -ForegroundColor Red

        exit
    }

    Restore-CpuName

    Write-Host ""
    Write-Host "按 Enter 键退出..."

    Read-Host

    exit
}


# ============================================================
# 正常安装模式
# ============================================================

if (!(Test-Administrator)) {

    Write-Host ""
    Write-Host "============================================"
    Write-Host "需要管理员权限运行。" `
        -ForegroundColor Red
    Write-Host "============================================"

    Write-Host ""
    Write-Host "请右键 PowerShell,选择:" `
        -ForegroundColor Yellow

    Write-Host "以管理员身份运行" `
        -ForegroundColor Yellow

    Write-Host ""

    Read-Host "按 Enter 键退出"

    exit
}


# ============================================================
# 开始安装
# ============================================================

Write-Host ""
Write-Host "============================================" `
    -ForegroundColor Cyan

Write-Host "       Windows CPU 名称修改工具" `
    -ForegroundColor Cyan

Write-Host "============================================" `
    -ForegroundColor Cyan


# ------------------------------------------------------------
# 创建目录
# ------------------------------------------------------------

Initialize-Directory


# ------------------------------------------------------------
# 显示原始 CPU
# ------------------------------------------------------------

$OriginalCpu = Get-CurrentCpuName

Write-Host ""
Write-Host "原来的 CPU:" `
    -ForegroundColor Yellow

Write-Host $OriginalCpu


# ------------------------------------------------------------
# 显示目标 CPU
# ------------------------------------------------------------

Write-Host ""
Write-Host "修改为:" `
    -ForegroundColor Yellow

Write-Host $CustomCpuName `
    -ForegroundColor Green


# ------------------------------------------------------------
# 备份
# ------------------------------------------------------------

Write-Host ""
Write-Host "正在备份原始 CPU 名称..." `
    -ForegroundColor Cyan

Backup-CpuName


# ------------------------------------------------------------
# 修改
# ------------------------------------------------------------

Write-Host ""
Write-Host "正在修改..." `
    -ForegroundColor Cyan

Set-CpuName


# ------------------------------------------------------------
# 创建开机任务
# ------------------------------------------------------------

Write-Host ""
Write-Host "正在设置开机自动修改..." `
    -ForegroundColor Cyan

Install-StartupTask


# ------------------------------------------------------------
# 最终结果
# ------------------------------------------------------------

Write-Host ""
Write-Host "============================================" `
    -ForegroundColor Green

Write-Host "                修改完成" `
    -ForegroundColor Green

Write-Host "============================================" `
    -ForegroundColor Green


Write-Host ""
Write-Host "当前 CPU 显示名称:" `
    -ForegroundColor Yellow

Write-Host (Get-CurrentCpuName) `
    -ForegroundColor Green


Write-Host ""
Write-Host "开机后会自动重新设置 CPU 名称。" `
    -ForegroundColor Green


Write-Host ""
Write-Host "原始名称备份:" `
    -ForegroundColor Gray

Write-Host $BackupFile


Write-Host ""
Write-Host "如需恢复原始名称,请执行:" `
    -ForegroundColor Yellow

Write-Host ""
Write-Host "powershell -ExecutionPolicy Bypass -File `"$ScriptPath`" -Restore" `
    -ForegroundColor Cyan


Write-Host ""
Read-Host "按 Enter 键退出"

3: 执行一下命令

bash 复制代码
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
Unblock-File -Path ".\CpuNameChanger.ps1"
.\CpuNameChanger.ps1
相关推荐
xx z18 小时前
哔哩哔哩第三方客户端 PiliPlus 实测:23.5MB 轻量版,手机平板电脑通用
智能手机·电脑
科小怪2 天前
ADB工具下载安装与常用命令:一条数据线连上电脑,就能给手机装应用、传文件、查日志
adb·智能手机·电脑
mg6683 天前
安卓玩机工具----安卓手机变成桌面电脑!多窗口镜像+音频投射+游戏操控,无需 Root
android·智能手机·电脑
迪康coolmu3 天前
企业U盘管控落地实战:基于迪康端点安全一体化管理系统的移动存储安全实践
运维·人工智能·经验分享·笔记·安全·电脑
sun861220773 天前
MiniMax M3.1 Flash 高效落地实战指南
电脑
冯小鸟的探戈4 天前
电脑重生之安装xp系统
运维·服务器·电脑
TST-魚爷5 天前
腾讯会议双机位同屏:前后两个摄像头画面合并显示方案(易视讯)
电脑·音视频·腾讯会议·zoom会议
七月稻草人5 天前
鸿蒙平板能当电脑第二块屏幕吗?ToDesk、向日葵镜像/副屏实测
华为·电脑·harmonyos
TST-魚爷6 天前
小型视频会议室音频踩坑:一体化拾音扩音方案实测分享(易视讯)
stm32·电脑·音视频·钉钉·腾讯会议·zoom会议
苏州福兰克6 天前
运行裸眼3D显示器对电脑显卡配置有什么要求?
3d·计算机外设·电脑