禁用笔记本键盘脚本

前言

在办公室时,笔记本拓展出两个外接显示器,笔记本放置在正前方显示器的下面时,没有空间放置我的机械键盘.只能把机械键盘放置在笔记本键盘上,出差时又需要使用笔记本自带的键盘;于是有了今天的这个脚本,用于快速开启与禁用笔记本脚本

bash 复制代码
@echo off
:: Check administrator privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo Requesting administrator privileges...
    powershell -Command "Start-Process cmd -ArgumentList '/c %~0' -Verb RunAs"
    goto :eof
)

echo ========================================
echo    PS/2 Driver Auto Toggle Script
echo ========================================
echo.

:: Check current i8042prt service status
echo Checking current PS/2 driver status...
for /f "tokens=4" %%a in ('sc qc i8042prt ^| findstr "START_TYPE"') do (
    set start_type=%%a
)

echo Raw start type: %start_type%
echo.

:: Convert start type to human readable (support both numeric and text)
if "%start_type%"=="2" (
    set current_state=ENABLED
) else if "%start_type%"=="3" (
    set current_state=DEMAND_START
) else if "%start_type%"=="4" (
    set current_state=DISABLED
) else if "%start_type%"=="AUTO_START" (
    set current_state=ENABLED
) else if "%start_type%"=="DEMAND_START" (
    set current_state=DEMAND_START
) else if "%start_type%"=="DISABLED" (
    set current_state=DISABLED
) else (
    echo [ERROR] Unknown start type: %start_type%
    echo Known types: 2/AUTO_START=Auto, 3/DEMAND_START=Demand, 4/DISABLED=Disabled
    pause
    exit /b 1
)

echo Current PS/2 driver state: %current_state%
echo.

:: Set the appropriate action based on current state
if "%current_state%"=="ENABLED" (
    echo PS/2 driver is currently ENABLED
    echo Switching to DISABLED state...
    sc config i8042prt start= disabled
    set new_state=DISABLED
    goto :check_result
) else if "%current_state%"=="DISABLED" (
    echo PS/2 driver is currently DISABLED
    echo Switching to ENABLED state...
    sc config i8042prt start= auto
    set new_state=ENABLED
    goto :check_result
) else if "%current_state%"=="DEMAND_START" (
    echo PS/2 driver is currently DEMAND_START (Manual)
    echo Switching to ENABLED state...
    sc config i8042prt start= auto
    set new_state=ENABLED
    goto :check_result
)

:check_result
if %errorlevel% equ 0 (
    echo.
    echo [SUCCESS] PS/2 driver is now %new_state%
    echo [NOTE] Restart required to take effect
    echo.
    choice /C YN /M "Restart computer now (Y/N)?"
    if errorlevel 2 (
        echo Please remember to restart computer manually
    ) else (
        shutdown /r /t 5
        echo Computer will restart in 5 seconds...
    )
) else (
    echo.
    echo [ERROR] Operation failed, error code: %errorlevel%
    echo Please check if the service name is correct
)

echo.
pause

功能很简单,就是自动切换管理员模式,然后识别你的i8042prt状态并切换,然后询问你是否立刻重启以生效.使用的时候只需要双击脚本即可.

相关推荐
ACP广源盛1392462567312 小时前
IX8024与科学大模型的碰撞@ACP#筑牢科研 AI 算力高速枢纽分享
运维·服务器·网络·数据库·人工智能·嵌入式硬件·电脑
humors22116 小时前
不同厂商电脑检测工具汇总
电脑·硬件·笔记本·检测·二手·正品·原件
舟遥遥娓飘飘18 小时前
Nexus4CC 手机电脑同步claude code对话部署教程(基于linux系统)
linux·智能手机·电脑
开开心心就好21 小时前
近200个工具的电脑故障修复合集
安全·智能手机·pdf·电脑·consul·memcache·1024程序员节
大飞记Python1 天前
刚从 Win 转 Mac?鼠标滚轮反向、触控板乱跑、第三方鼠标卡顿——这一篇就够了
macos·计算机外设·mac鼠标
优选资源分享2 天前
Pixelscope v8 屏幕放大镜 | Windows 轻量化鼠标跟随放大工具
计算机外设
humors2212 天前
电脑厂商旧机处理网址合集(不定期更新)
电脑·笔记本·处理·回收·以旧换新·二手·买卖
humors2212 天前
不同品牌电脑进入 BIOS 及启动菜单的快捷键
电脑·快捷键·启动·笔记本
zB6822HbX2 天前
Ledger设备连接不上电脑?秘语盾排查指南
电脑
humors2212 天前
家庭电脑从选购、安装、维护到回收全流程
电脑·安装·笔记本·回收·维护·选购·购买