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

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
相关推荐
可爱系程序猿1 小时前
ARM电脑安装打印机驱动失败:先辨认安装器、系统架构与打印路径
arm开发·程序人生·电脑
我不是程序员三三2 小时前
怎么监控电脑?企业办公终端监控建设实战与合规要点
服务器·数据库·电脑
乌萨达3 小时前
王者万象棋电脑版怎么下载?PC端安装、模拟器运行及配置教程
游戏·电脑·安卓模拟器·雷电模拟器
云边有个稻草人1 天前
手机操作电脑的软件哪个好?5款手机远控电脑横评
智能手机·电脑
一支标2 天前
【手机+电脑】通达信《K策王》策略战法K策王技术副图指标使用说明
大数据·智能手机·电脑
开开心心就好2 天前
免费刷题软件推荐,支持导入题库自动判题
网络·网络协议·tcp/ip·jupyter·智能手机·电脑·idea
bj_bluewei_tech2 天前
联想拯救者卡 LOGO 无限重启 低温锡虚焊不用直接更换主板
电脑·笔记本电脑
kakakahahahaha2 天前
Windows重装后D盘要求48位BitLocker恢复密钥的排查与处理
windows·电脑·内容运营·软件需求
wind100323 天前
DLSS5 开启保姆级教程:RTX20/30/40 显卡通用 鸣潮 / 异环 / 绝区零全适配
游戏·电脑·英伟达·dlss·鸣潮