(view source code of wmialias.bat as plain text)
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
:: Check command line and WMIC availability
IF NOT "%~2"=="" GOTO Syntax
IF "%~1"=="/?" GOTO Syntax
WMIC /? >NUL 2>&1 || GOTO Syntax
SET SortOrder=ByAlias
SET Alias=
IF NOT "%~1"=="" (
IF /I "%~1"=="/SORT" (
SET SortOrder=ByClassName
) ELSE (
REM Alias consists of 2 or more letters, no other characters allowed
ECHO "%~1"| FINDSTR.EXE /R /X /I /C:"\""[a-z][a-z][a-z]*\""" >NUL 2>&1
IF ERRORLEVEL 1 GOTO Syntax
SET Alias=%~1
)
)
CALL :List
ENDLOCAL
GOTO:EOF
:List
ECHO ALIAS: WMI CLASS NAME:
ECHO.====== ===============
SET AliasList=
SET ClassList=
FOR /F "skip=1 tokens=1,5" %%A IN ('WMIC ALIAS %1 Get FriendlyName^,Target') DO (
REM Append 20 spaces to alias
SET AliasList.%%A=%%A
SET ClassList.%%B=%%A
REM Chop alias plus spaces at 20 characters
SET AliasList.%%A=!AliasList.%%A:~0,20!
SET ClassList.%%B=!ClassList.%%B:~0,20!
REM Append class name
SET AliasList.%%A=!AliasList.%%A! %%B
SET ClassList.%%B=!ClassList.%%B! %%B
)
IF "%SortOrder%"=="ByClassName" (
FOR /F "tokens=1* delims==" %%A IN ('SET ClassList') DO ECHO.%%B
) ELSE IF NOT "%Alias%"=="" (
FOR /F "tokens=1* delims==" %%A IN ('SET AliasList ^| FIND /I "=%Alias%"') DO ECHO.%%B
) ELSE (
FOR /F "tokens=1* delims==" %%A IN ('SET AliasList') DO ECHO.%%B
)
GOTO:EOF
:Syntax
ECHO.
ECHO WMIAlias.bat, Version 1.01 for Windows XP professional and later
ECHO Return WMI class name for specified WMIC alias, or list all if none specified
ECHO.
ECHO Usage: WMIALIAS [ alias ^| /SORT ]
ECHO.
ECHO Where: alias is a WMIC alias, e.g. "bios" for the "Win32_BIOS" class
ECHO /SORT sort output by WMI class name (default: sort by WMIC alias)
ECHO.
ECHO Notes: If no alias is specified, all WMIC aliases and their WMI class names
ECHO will be listed.
ECHO Listed output is sorted by WMIC alias name by default, or by WMI class
ECHO name if the /SORT switch is used.
ECHO.
ECHO Written by Rob van der Woude
ECHO https://www.robvanderwoude.com
ENDLOCAL
EXIT /B 1
page last modified: 2024-04-16; loaded in 0.0055 seconds