禁用笔记本键盘脚本

前言

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

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状态并切换,然后询问你是否立刻重启以生效.使用的时候只需要双击脚本即可.

相关推荐
呉師傅5 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
一个人旅程~5 天前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑
JXSJHF5 天前
怎么在你的电脑里 “再装一台电脑”?
电脑
神奇程序员5 天前
不止高刷:明基 RD280UG 在编码场景下的表现如何
计算机外设
开开心心就好5 天前
安卓开源应用,超时提醒紧急人护独居安全
windows·决策树·计算机视觉·pdf·计算机外设·excel·动态规划
上海合宙LuatOS5 天前
LuatOS核心库API——【iotauth 】 IOT 鉴权库
java·单片机·嵌入式硬件·物联网·struts·计算机外设·硬件工程
谁刺我心6 天前
qml自定义鼠标
计算机外设
一个人旅程~6 天前
win10LTSB2016与win10LTSC2019对于老机型哪个更合适?
linux·windows·经验分享·电脑
刘恒1234567896 天前
Windows 电脑文件夹手动分类指南
java·windows·python·电脑·php
SamtecChina20236 天前
Samtec连接器设计研究 | 载流量:温升为什么重要?
大数据·网络·人工智能·算法·计算机外设