test-1.bat
根据 ChassisTypes 判断
https://devblogs.microsoft.com/scripting/how-can-i-determine-if-a-computer-is-a-laptop-or-a-desktop-machine- @echo off
- for /f "tokens=2 delims={}" %%i in ('wmic Path Win32_SystemEnclosure get ChassisTypes /value') do (
- set "CompType=%%i"
- )
- if "%CompType%" equ "3" (
- echo 台式机
- ) else if "%CompType%" equ "10" (
- echo 笔记本
- ) else (
- echo 未知
- )
- pause
复制代码 test-2.bat
根据 PCSystemType 判断
https://learn.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.pcsystemtype?view=powershellsdk-1.1.0- @echo off
- for /f "tokens=2 delims==" %%i in ('wmic ComputerSystem get PCSystemType /value') do (
- for %%a in ("%%i") do (
- set "CompType=%%~a"
- )
- )
- if "%CompType%" equ "1" (
- echo 台式机
- ) else if "%CompType%" equ "2" (
- echo 笔记本
- ) else (
- echo 未知
- )
- pause
复制代码 test-3.bat
根据 PCSystemType 判断
https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-battery- @echo off
- for /f "tokens=2 delims==" %%i in ('wmic Path Win32_Battery Get BatteryStatus 2^>nul') do (
- for %%a in ("%%i") do (
- set "BatteryValue=%%~a"
- )
- )
- if "%BatteryValue%" equ "1" (
- echo 笔记本
- ) else if "%BatteryValue%" equ "2" (
- echo 笔记本
- ) else (
- echo 台式机
- )
- pause
复制代码 test-4.bat
综合多个条件进行判断- @echo off
- set "DesktopVote=0"
- set "LaptopVote=0"
-
- for /f "tokens=2 delims={}" %%i in ('wmic Path Win32_SystemEnclosure get ChassisTypes /value') do (
- set "CompType=%%i"
- )
- if "%CompType%" equ "3" (
- set /a DesktopVote+=1
- ) else if "%CompType%" equ "10" (
- set /a LaptopVote+=1
- )
-
- for /f "tokens=2 delims==" %%i in ('wmic ComputerSystem get PCSystemType /value') do (
- for %%a in ("%%i") do (
- set "CompType=%%~a"
- )
- )
- if "%CompType%" equ "1" (
- set /a DesktopVote+=1
- ) else if "%CompType%" equ "2" (
- set /a LaptopVote+=1
- )
-
- for /f "tokens=2 delims==" %%i in ('wmic Path Win32_Battery Get BatteryStatus /value 2^>nul') do (
- for %%a in ("%%i") do (
- set "BatteryValue=%%~a"
- )
- )
- if "%BatteryValue%" equ "1" (
- set /a LaptopVote+=1
- ) else if "%BatteryValue%" equ "2" (
- set /a LaptopVote+=1
- ) else (
- set /a DesktopVote+=1
- )
-
- if %LaptopVote% gtr %DesktopVote% (
- echo 笔记本
- ) else if %LaptopVote% lss %DesktopVote% (
- echo 台式机
- ) else (
- echo 未知
- )
- pause
复制代码
|