首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >工控机电源策略强化部署工具--禁止电脑休眠

工控机电源策略强化部署工具--禁止电脑休眠

作者头像
科控物联
发布2026-03-19 13:15:00
发布2026-03-19 13:15:00
1560
举报

为社么要禁止工控机休眠?

🏭 一、生产连续性与稳定性

1. 避免生产中断

  • 7×24小时不间断运行:确保生产线连续作业,避免因设备休眠导致的意外停产
  • 消除重启延迟:休眠后恢复需要时间,禁止休眠可立即响应生产指令

2. 保持实时控制

  • 实时数据采集:确保PLC、传感器数据持续采集不中断
  • 即时控制响应:避免因系统休眠导致的控制指令延迟执行

二、系统可靠性提升

1. 减少硬件故障风险

  • 避免频繁电源切换:休眠/唤醒过程中的电源波动可能损坏硬件
  • 保持稳定运行状态:连续运行比频繁状态切换更有利于设备寿命

2. 防止软件异常

  • 避免驱动兼容问题:某些工业设备驱动在休眠后可能出现异常
  • 保持网络连接稳定:防止休眠导致的网络断开和重连问题

🔧 三、维护与管理便利性

1. 远程监控可靠性

  • 持续远程访问:运维人员可随时远程连接,无需担心设备处于休眠状态
  • 实时故障诊断:发现问题可立即远程排查,无需现场唤醒设备

2. 简化系统管理

  • 统一运行状态:所有工控机保持相同运行状态,便于集中管理
  • 减少维护工作量:无需处理因休眠引起的各种异常问题

📊 四、数据完整性与安全性

1. 确保数据不丢失

  • 实时数据保存:生产数据、日志信息持续写入,避免休眠时数据丢失风险
  • 保持数据库连接:防止数据库连接因休眠中断导致数据不一致

2. 安全监控不间断

  • 持续安全监控:安防系统、门禁系统等保持全天候运行
  • 实时报警响应:确保安全警报能够立即被处理,不因系统休眠而延误

💻 五、性能优化

1. 保持最佳性能状态

  • 避免性能波动:休眠恢复后系统可能需要时间达到最佳性能状态
  • 资源立即可用:CPU、内存等资源始终处于就绪状态

2. 优化工业软件运行

  • 专业软件兼容性:许多工业控制软件不建议在可休眠环境中运行
  • 保持计算连续性:确保长时间运算任务不被中断

🛡️ 六、合规性与标准符合

1. 符合行业标准

  • 工业自动化标准:多数工业环境要求设备7×24小时运行
  • 安全认证要求:某些安全认证禁止生产设备自动休眠

2. 满足客户要求

  • 客户合同条款:很多制造合同明确要求生产设备不间断运行
  • 质量体系认证:ISO等质量体系要求生产环境稳定性

📋 七、实际应用场景 benefits

典型应用场景

  1. 流水线生产控制 - 避免因休眠导致整条生产线停产
  2. 过程监控系统 - 确保实时监控数据不丢失
  3. 数据采集服务器 - 保持与现场设备的持续通信
  4. 安防监控中心 - 确保监控系统全天候运行
  5. 实验室测试设备 - 保证长时间测试的连续性

本脚本可以直接copy到power shell运行。也可以保存为psl后执行

保存建议:

用记事本打开

复制上面的修正代码

文件 → 另存为

文件名:Disable-Sleep.ps1

保存类型:所有文件

编码:ANSI

运行:

代码语言:javascript
复制
powershell -ExecutionPolicy Bypass -File ".\Disable-Sleep.ps1"

运行脚本效果:

脚本:

代码语言:javascript
复制
# 工控机电源策略强化工具
# 科控物联 QQ: 2492123056
# 生产线专用 - 确保7x24小时不间断运行
# 检查管理员权限
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
    Write-Host "错误:请使用管理员权限运行此脚本!" -ForegroundColor Red
    Write-Host "右键点击 PowerShell 图标,选择以管理员身份运行" -ForegroundColor Yellow
    pause
    exit
}
# 初始化错误计数器
$errorCount = 0
$successCount = 0
Write-Host ""
Write-Host "==================================================" -ForegroundColor Green
Write-Host "   工控机电源策略强化部署工具" -ForegroundColor Red
Write-Host "   科控物联 QQ: 2492123056" -ForegroundColor Green 
Write-Host "==================================================" -ForegroundColor Green
Write-Host "正在禁用所有休眠功能..." -ForegroundColor Yellow
# 1. 禁用休眠功能
Write-Host ""
Write-Host "[1/7] 正在禁用休眠功能..." -ForegroundColor Cyan
try {
    $result = powercfg -h off 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Host "   完成 休眠功能已禁用" -ForegroundColor Green
        $successCount++
    } else {
        Write-Host "   失败 无法禁用休眠功能" -ForegroundColor Red
        Write-Host "   错误信息: $result" -ForegroundColor Red
        $errorCount++
    }
} catch {
    Write-Host "   失败 执行禁用休眠时发生异常" -ForegroundColor Red
    $errorCount++
}
# 2. 禁用屏幕保护程序
Write-Host ""
Write-Host "[2/7] 正在禁用屏幕保护程序..." -ForegroundColor Cyan
try {
    $result1 = reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 0 /f 2>&1
    $result2 = reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d 0 /f 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Host "   完成 屏幕保护程序已禁用" -ForegroundColor Green
        $successCount++
    } else {
        Write-Host "   失败 无法禁用屏幕保护程序" -ForegroundColor Red
        Write-Host "   错误信息: $result1 $result2" -ForegroundColor Red
        $errorCount++
    }
} catch {
    Write-Host "   失败 执行禁用屏幕保护时发生异常" -ForegroundColor Red
    $errorCount++
}
# 3. 设置显示器和硬盘永不休眠
Write-Host ""
Write-Host "[3/7] 正在设置显示器和硬盘超时..." -ForegroundColor Cyan
try {
    $commands = @(
        "powercfg -change -standby-timeout-ac 0",
        "powercfg -change -standby-timeout-dc 0",
        "powercfg -change -monitor-timeout-ac 0",
        "powercfg -change -monitor-timeout-dc 0",
        "powercfg -change -disk-timeout-ac 0",
        "powercfg -change -disk-timeout-dc 0"
    )

    $allSuccess = $true
    foreach ($cmd in $commands) {
        $result = Invoke-Expression $cmd 2>&1
        if ($LASTEXITCODE -ne 0) {
            $allSuccess = $false
            Write-Host "   警告 命令执行失败: $cmd" -ForegroundColor Yellow
        }
    }

    if ($allSuccess) {
        Write-Host "   完成 显示器和硬盘永不休眠" -ForegroundColor Green
        $successCount++
    } else {
        Write-Host "   部分失败 某些超时设置可能未生效" -ForegroundColor Yellow
        $errorCount++
    }
} catch {
    Write-Host "   失败 设置超时时发生异常" -ForegroundColor Red
    $errorCount++
}
# 4. 禁用混合睡眠
Write-Host ""
Write-Host "[4/7] 正在禁用混合睡眠..." -ForegroundColor Cyan
try {
    $result1 = powercfg -setacvalueindex SCHEME_CURRENT 238c9fa8-0aad-41ed-83f4-97be242c8f20 94ac6d29-73ce-41a6-809f-6363ba21b47e 0 2>&1
    $result2 = powercfg -setdcvalueindex SCHEME_CURRENT 238c9fa8-0aad-41ed-83f4-97be242c8f20 94ac6d29-73ce-41a6-809f-6363ba21b47e 0 2>&1

    if ($LASTEXITCODE -eq 0) {
        Write-Host "   完成 混合睡眠已禁用" -ForegroundColor Green
        $successCount++
    } else {
        Write-Host "   失败 无法禁用混合睡眠" -ForegroundColor Red
        Write-Host "   错误信息: $result1 $result2" -ForegroundColor Red
        $errorCount++
    }
} catch {
    Write-Host "   失败 禁用混合睡眠时发生异常" -ForegroundColor Red
    $errorCount++
}
# 5. 禁用无人参与睡眠
Write-Host ""
Write-Host "[5/7] 正在禁用无人参与睡眠..." -ForegroundColor Cyan
try {
    $result1 = powercfg -setacvalueindex SCHEME_CURRENT 238c9fa8-0aad-41ed-83f4-97be242c8f20 29f6c1db-86da-48c5-9fdb-f2b67b1f44da 0 2>&1
    $result2 = powercfg -setdcvalueindex SCHEME_CURRENT 238c9fa8-0aad-41ed-83f4-97be242c8f20 29f6c1db-86da-48c5-9fdb-f2b67b1f44da 0 2>&1

    if ($LASTEXITCODE -eq 0) {
        Write-Host "   完成 无人参与睡眠已禁用" -ForegroundColor Green
        $successCount++
    } else {
        Write-Host "   失败 无法禁用无人参与睡眠" -ForegroundColor Red
        Write-Host "   错误信息: $result1 $result2" -ForegroundColor Red
        $errorCount++
    }
} catch {
    Write-Host "   失败 禁用无人参与睡眠时发生异常" -ForegroundColor Red
    $errorCount++
}
# 6. 禁用快速启动
Write-Host ""
Write-Host "[6/7] 正在禁用快速启动..." -ForegroundColor Cyan
try {
    $result = reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /v HiberbootEnabled /t REG_DWORD /d 0 /f 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Host "   完成 快速启动已禁用" -ForegroundColor Green
        $successCount++
    } else {
        Write-Host "   失败 无法禁用快速启动" -ForegroundColor Red
        Write-Host "   错误信息: $result" -ForegroundColor Red
        $errorCount++
    }
} catch {
    Write-Host "   失败 禁用快速启动时发生异常" -ForegroundColor Red
    $errorCount++
}
# 7. 应用高性能电源方案
Write-Host ""
Write-Host "[7/7] 正在设置高性能电源方案..." -ForegroundColor Cyan
try {
    $result = powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Host "   完成 高性能方案已激活" -ForegroundColor Green
        $successCount++
    } else {
        Write-Host "   失败 无法激活高性能方案" -ForegroundColor Red
        Write-Host "   错误信息: $result" -ForegroundColor Red
        $errorCount++
    }
} catch {
    Write-Host "   失败 激活高性能方案时发生异常" -ForegroundColor Red
    $errorCount++
}
# 验证结果
Write-Host ""
Write-Host "==================================================" -ForegroundColor Green
Write-Host "验证配置状态..." -ForegroundColor Green
Write-Host "==================================================" -ForegroundColor Green
try {
    $sleepState = powercfg -a 2>&1
    if ($LASTEXITCODE -eq 0) {
        if ($sleepState -like "*Standby (S3)*") {
            Write-Host "警告:系统仍支持睡眠状态,请手动检查!" -ForegroundColor Yellow
            Write-Host "请检查控制面板中的电源选项" -ForegroundColor Yellow
        } else {
            Write-Host "成功:所有睡眠功能已禁用" -ForegroundColor Green
        }
    } else {
        Write-Host "警告:无法验证睡眠状态" -ForegroundColor Yellow
    }
} catch {
    Write-Host "验证睡眠状态时发生错误" -ForegroundColor Red
}
# 显示最终结果统计
Write-Host ""
Write-Host "==================================================" -ForegroundColor Green
Write-Host "部署完成统计:" -ForegroundColor Cyan
Write-Host "成功项目: $successCount/7" -ForegroundColor Green
Write-Host "失败项目: $errorCount/7" -ForegroundColor $(if ($errorCount -gt 0) { "Red" } else { "Green" })
Write-Host "==================================================" -ForegroundColor Green
if ($errorCount -gt 0) {
    Write-Host "注意:有 $errorCount 个项目设置失败!" -ForegroundColor Red
    Write-Host "建议检查系统权限或手动设置电源选项" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "重要建议:" -ForegroundColor Cyan
Write-Host "1. 立即重启计算机" -ForegroundColor White
Write-Host "2. 检查控制面板中的电源选项" -ForegroundColor White
Write-Host "3. 确认所有睡眠选项设置为从不" -ForegroundColor White
Write-Host "4. 确保没有自动维护任务" -ForegroundColor White
Write-Host ""
Write-Host "==================================================" -ForegroundColor Green
Write-Host "此配置确保24小时不间断运行" -ForegroundColor Red
Write-Host "==================================================" -ForegroundColor Green
# 重启提示
$restart = Read-Host "是否立即重启计算机?(y/n)"
if ($restart -eq 'y' -or $restart -eq 'Y') {
    Write-Host "正在重启计算机..." -ForegroundColor Yellow
    Restart-Computer -Force
} else {
    Write-Host ""
    Write-Host "请手动重启以完成设置!" -ForegroundColor Yellow
    Write-Host "按任意键退出..." -ForegroundColor Yellow
    pause
}

如果需要日志,可以参考下面的脚本:

代码语言:javascript
复制
# 工控机电源策略强化工具 - 完整优化版
# 科控物联 QQ: 2492123056
# 生产线专用 - 确保7x24小时不间断运行
# 初始化日志系统
$logDir = "C:\PowerConfigLogs"
$logFile = "$logDir\PowerConfig_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
# 创建日志目录
if (!(Test-Path $logDir)) {
    New-Item -ItemType Directory -Path $logDir -Force | Out-Null
}
# 日志记录函数
function Write-Log {
    param(
        [string]$Message,
        [string]$Level = "INFO"
    )

    $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    $logEntry = "$timestamp [$Level] $Message"

    # 输出到屏幕
    switch ($Level) {
        "ERROR" { Write-Host $logEntry -ForegroundColor Red }
        "WARN"  { Write-Host $logEntry -ForegroundColor Yellow }
        "INFO"  { Write-Host $logEntry -ForegroundColor White }
        "SUCCESS" { Write-Host $logEntry -ForegroundColor Green }
        default { Write-Host $logEntry }
    }

    # 写入日志文件
    Add-Content -Path $logFile -Value $logEntry -Encoding UTF8
}
# 检查管理员权限
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
    Write-Log "错误:请使用管理员权限运行此脚本!" "ERROR"
    Write-Log "右键点击 PowerShell 图标,选择以管理员身份运行" "WARN"
    pause
    exit
}
# 初始化错误计数器
$errorCount = 0
$successCount = 0
Write-Log "==================================================" "INFO"
Write-Log "   工控机电源策略强化部署工具" "INFO"
Write-Log "   科控物联 QQ: 2492123056" "INFO"
Write-Log "   日志文件: $logFile" "INFO"
Write-Log "==================================================" "INFO"
Write-Log "正在禁用所有休眠功能..." "INFO"
# 记录系统信息
Write-Log "系统信息收集开始..." "INFO"
Write-Log "计算机名: $env:COMPUTERNAME" "INFO"
Write-Log "用户名: $env:USERNAME" "INFO"
Write-Log "操作系统: $(Get-WmiObject -Class Win32_OperatingSystem).Caption" "INFO"
Write-Log "系统架构: $(Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture" "INFO"
# 1. 禁用休眠功能
Write-Log "[1/7] 正在禁用休眠功能..." "INFO"
try {
    $result = powercfg -h off 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Log "完成 休眠功能已禁用" "SUCCESS"
        $successCount++
    } else {
        Write-Log "失败 无法禁用休眠功能" "ERROR"
        Write-Log "错误信息: $result" "ERROR"
        $errorCount++
    }
} catch {
    Write-Log "失败 执行禁用休眠时发生异常: $($_.Exception.Message)" "ERROR"
    $errorCount++
}
# 2. 禁用屏幕保护程序
Write-Log "[2/7] 正在禁用屏幕保护程序..." "INFO"
try {
    $result1 = reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 0 /f 2>&1
    $result2 = reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d 0 /f 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Log "完成 屏幕保护程序已禁用" "SUCCESS"
        $successCount++
    } else {
        Write-Log "失败 无法禁用屏幕保护程序" "ERROR"
        Write-Log "错误信息: $result1 $result2" "ERROR"
        $errorCount++
    }
} catch {
    Write-Log "失败 执行禁用屏幕保护时发生异常: $($_.Exception.Message)" "ERROR"
    $errorCount++
}
# 3. 设置显示器和硬盘永不休眠
Write-Log "[3/7] 正在设置显示器和硬盘超时..." "INFO"
try {
    $commands = @(
        "powercfg -change -standby-timeout-ac 0",
        "powercfg -change -standby-timeout-dc 0",
        "powercfg -change -monitor-timeout-ac 0",
        "powercfg -change -monitor-timeout-dc 0",
        "powercfg -change -disk-timeout-ac 0",
        "powercfg -change -disk-timeout-dc 0"
    )

    $allSuccess = $true
    foreach ($cmd in $commands) {
        $result = Invoke-Expression $cmd 2>&1
        if ($LASTEXITCODE -ne 0) {
            $allSuccess = $false
            Write-Log "警告 命令执行失败: $cmd" "WARN"
            Write-Log "错误信息: $result" "WARN"
        }
    }

    if ($allSuccess) {
        Write-Log "完成 显示器和硬盘永不休眠" "SUCCESS"
        $successCount++
    } else {
        Write-Log "部分失败 某些超时设置可能未生效" "WARN"
        $errorCount++
    }
} catch {
    Write-Log "失败 设置超时时发生异常: $($_.Exception.Message)" "ERROR"
    $errorCount++
}
# 4. 禁用混合睡眠
Write-Log "[4/7] 正在禁用混合睡眠..." "INFO"
try {
    $result1 = powercfg -setacvalueindex SCHEME_CURRENT 238c9fa8-0aad-41ed-83f4-97be242c8f20 94ac6d29-73ce-41a6-809f-6363ba21b47e 0 2>&1
    $result2 = powercfg -setdcvalueindex SCHEME_CURRENT 238c9fa8-0aad-41ed-83f4-97be242c8f20 94ac6d29-73ce-41a6-809f-6363ba21b47e 0 2>&1

    if ($LASTEXITCODE -eq 0) {
        Write-Log "完成 混合睡眠已禁用" "SUCCESS"
        $successCount++
    } else {
        Write-Log "失败 无法禁用混合睡眠" "ERROR"
        Write-Log "错误信息: $result1 $result2" "ERROR"
        $errorCount++
    }
} catch {
    Write-Log "失败 禁用混合睡眠时发生异常: $($_.Exception.Message)" "ERROR"
    $errorCount++
}
# 5. 禁用无人参与睡眠
Write-Log "[5/7] 正在禁用无人参与睡眠..." "INFO"
try {
    $result1 = powercfg -setacvalueindex SCHEME_CURRENT 238c9fa8-0aad-41ed-83f4-97be242c8f20 29f6c1db-86da-48c5-9fdb-f2b67b1f44da 0 2>&1
    $result2 = powercfg -setdcvalueindex SCHEME_CURRENT 238c9fa8-0aad-41ed-83f4-97be242c8f20 29f6c1db-86da-48c5-9fdb-f2b67b1f44da 0 2>&1

    if ($LASTEXITCODE -eq 0) {
        Write-Log "完成 无人参与睡眠已禁用" "SUCCESS"
        $successCount++
    } else {
        Write-Log "失败 无法禁用无人参与睡眠" "ERROR"
        Write-Log "错误信息: $result1 $result2" "ERROR"
        $errorCount++
    }
} catch {
    Write-Log "失败 禁用无人参与睡眠时发生异常: $($_.Exception.Message)" "ERROR"
    $errorCount++
}
# 6. 禁用快速启动
Write-Log "[6/7] 正在禁用快速启动..." "INFO"
try {
    $result = reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /v HiberbootEnabled /t REG_DWORD /d 0 /f 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Log "完成 快速启动已禁用" "SUCCESS"
        $successCount++
    } else {
        Write-Log "失败 无法禁用快速启动" "ERROR"
        Write-Log "错误信息: $result" "ERROR"
        $errorCount++
    }
} catch {
    Write-Log "失败 禁用快速启动时发生异常: $($_.Exception.Message)" "ERROR"
    $errorCount++
}
# 7. 应用高性能电源方案
Write-Log "[7/7] 正在设置高性能电源方案..." "INFO"
try {
    $result = powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Log "完成 高性能方案已激活" "SUCCESS"
        $successCount++
    } else {
        Write-Log "失败 无法激活高性能方案" "ERROR"
        Write-Log "错误信息: $result" "ERROR"
        $errorCount++
    }
} catch {
    Write-Log "失败 激活高性能方案时发生异常: $($_.Exception.Message)" "ERROR"
    $errorCount++
}
# 验证结果
Write-Log "==================================================" "INFO"
Write-Log "验证配置状态..." "INFO"
Write-Log "==================================================" "INFO"
try {
    $sleepState = powercfg -a 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Log "电源状态检测结果:" "INFO"
        Write-Log "------------------------------------------" "INFO"

        # 格式化输出电源状态信息
        $sleepStateLines = $sleepState -split "`r`n"
        foreach ($line in $sleepStateLines) {
            if ($line.Trim() -ne "") {
                Write-Log "  $($line.Trim())" "INFO"
            }
        }

        Write-Log "------------------------------------------" "INFO"

        # 修正检测逻辑
        if ($sleepState -like "*待机 (S3)*" -and $sleepState -notlike "*不支持此待机状态*") {
            Write-Log "信息:硬件支持待机(S3)状态(正常)" "INFO"
            Write-Log "但电源策略已设置为永不休眠" "INFO"
        } else {
            Write-Log "成功:待机(S3)状态已禁用或不受支持" "SUCCESS"
        }

        if ($sleepState -like "*休眠*" -and $sleepState -notlike "*尚未启用休眠*" -and $sleepState -notlike "*休眠不可用*") {
            Write-Log "警告:系统仍支持休眠状态!" "WARN"
        } else {
            Write-Log "成功:休眠状态已禁用" "SUCCESS"
        }

        if ($sleepState -like "*混合睡眠*" -and $sleepState -notlike "*休眠不可用*") {
            Write-Log "警告:系统仍支持混合睡眠!" "WARN"
        } else {
            Write-Log "成功:混合睡眠已禁用" "SUCCESS"
        }

        # 检查快速启动注册表项来确认状态
        $fastBoot = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power" -Name "HiberbootEnabled" -ErrorAction SilentlyContinue
        if ($fastBoot -and $fastBoot.HiberbootEnabled -eq 0) {
            Write-Log "成功:快速启动已禁用" "SUCCESS"
        } else {
            Write-Log "警告:快速启动可能仍启用!" "WARN"
        }

    } else {
        Write-Log "警告:无法验证睡眠状态" "WARN"
        Write-Log "错误信息: $sleepState" "WARN"
    }
} catch {
    Write-Log "验证睡眠状态时发生错误: $($_.Exception.Message)" "ERROR"
}
# 显示最终结果统计
Write-Log "==================================================" "INFO"
Write-Log "部署完成统计:" "INFO"
Write-Log "成功项目: $successCount/7" $(if ($successCount -eq 7) { "SUCCESS" } else { "INFO" })
Write-Log "失败项目: $errorCount/7" $(if ($errorCount -gt 0) { "ERROR" } else { "INFO" })
Write-Log "日志文件: $logFile" "INFO"
Write-Log "==================================================" "INFO"
# 记录最终状态到日志
Write-Log "最终状态: 成功 $successCount 项, 失败 $errorCount 项" "INFO"
Write-Log "脚本执行完成时间: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" "INFO"
if ($errorCount -gt 0) {
    Write-Log "注意:有 $errorCount 个项目设置失败!" "ERROR"
    Write-Log "建议检查系统权限或手动设置电源选项" "WARN"
}
Write-Log ""
Write-Log "重要建议:" "INFO"
Write-Log "1. 立即重启计算机" "INFO"
Write-Log "2. 检查控制面板中的电源选项" "INFO"
Write-Log "3. 确认所有睡眠选项设置为从不" "INFO"
Write-Log "4. 确保没有自动维护任务" "INFO"
Write-Log "==================================================" "INFO"
Write-Log "此配置确保24小时不间断运行" "INFO"
Write-Log "==================================================" "INFO"
# 重启提示
$restart = Read-Host "是否立即重启计算机?(y/n)"
if ($restart -eq 'y' -or $restart -eq 'Y') {
    Write-Log "用户选择立即重启计算机" "INFO"
    Write-Log "正在重启计算机..." "INFO"
    Restart-Computer -Force
} else {
    Write-Log "用户选择不立即重启" "INFO"
    Write-Log "请手动重启以完成设置!" "WARN"
    Write-Log "按任意键退出..." "INFO"
    pause
}

日志

重启电脑后查看状态:

代码语言:javascript
复制
# 检查电源设置 
powercfg -q 
powercfg -a  
# 检查快速启动状态 
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /v HiberbootEnabled
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2025-09-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 科控物联 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 为社么要禁止工控机休眠?
  • 🏭 一、生产连续性与稳定性
    • 1. 避免生产中断
    • 2. 保持实时控制
  • ⚡ 二、系统可靠性提升
    • 1. 减少硬件故障风险
    • 2. 防止软件异常
  • 🔧 三、维护与管理便利性
    • 1. 远程监控可靠性
    • 2. 简化系统管理
  • 📊 四、数据完整性与安全性
    • 1. 确保数据不丢失
    • 2. 安全监控不间断
  • 💻 五、性能优化
    • 1. 保持最佳性能状态
    • 2. 优化工业软件运行
  • 🛡️ 六、合规性与标准符合
    • 1. 符合行业标准
    • 2. 满足客户要求
  • 📋 七、实际应用场景 benefits
    • 典型应用场景:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档