前言
在办公室时,笔记本拓展出两个外接显示器,笔记本放置在正前方显示器的下面时,没有空间放置我的机械键盘.只能把机械键盘放置在笔记本键盘上,出差时又需要使用笔记本自带的键盘;于是有了今天的这个脚本,用于快速开启与禁用笔记本脚本
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状态并切换,然后询问你是否立刻重启以生效.使用的时候只需要双击脚本即可.