Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for wmialias.bat

(view source code of wmialias.bat as plain text)

  1. @ECHO OFF
  2. SETLOCAL ENABLEDELAYEDEXPANSION
  3.  
  4. :: Check command line and WMIC availability
  5. IF NOT  "%~2"==""     GOTO Syntax
  6. IF      "%~1"=="/?"   GOTO Syntax
  7. WMIC /? >NUL 2>&1  || GOTO Syntax
  8.  
  9. SET SortOrder=ByAlias
  10. SET Alias=
  11.  
  12. IF NOT "%~1"=="" (
  13. 	IF /I "%~1"=="/SORT" (
  14. 		SET SortOrder=ByClassName
  15. 	) ELSE (
  16. 		REM Alias consists of 2 or more letters, no other characters allowed
  17. 		ECHO "%~1"| FINDSTR.EXE /R /X /I /C:"\""[a-z][a-z][a-z]*\""" >NUL 2>&1
  18. 		IF ERRORLEVEL 1 GOTO Syntax
  19. 		SET Alias=%~1
  20. 	)
  21. )
  22.  
  23. CALL :List
  24.  
  25. ENDLOCAL
  26. GOTO:EOF
  27.  
  28.  
  29. :List
  30. ECHO ALIAS:                      WMI CLASS NAME:
  31. ECHO.======                      ===============
  32.  
  33. SET AliasList=
  34. SET ClassList=
  35.  
  36. FOR /F "skip=1 tokens=1,5" %%A IN ('WMIC ALIAS %1 Get FriendlyName^,Target') DO (
  37. 	REM Append 20 spaces to alias
  38. 	SET AliasList.%%A=%%A                    
  39. 	SET ClassList.%%B=%%A                    
  40. 	REM Chop alias plus spaces at 20 characters
  41. 	SET AliasList.%%A=!AliasList.%%A:~0,20!
  42. 	SET ClassList.%%B=!ClassList.%%B:~0,20!
  43. 	REM Append class name
  44. 	SET AliasList.%%A=!AliasList.%%A!        %%B
  45. 	SET ClassList.%%B=!ClassList.%%B!        %%B
  46. )
  47.  
  48. IF "%SortOrder%"=="ByClassName" (
  49. 	FOR /F "tokens=1* delims==" %%A IN ('SET ClassList') DO ECHO.%%B
  50. ) ELSE IF NOT "%Alias%"=="" (
  51. 	FOR /F "tokens=1* delims==" %%A IN ('SET AliasList ^| FIND /I "=%Alias%"') DO ECHO.%%B
  52. ) ELSE (
  53. 	FOR /F "tokens=1* delims==" %%A IN ('SET AliasList') DO ECHO.%%B
  54. )
  55. GOTO:EOF
  56.  
  57.  
  58. :Syntax
  59. ECHO.
  60. ECHO WMIAlias.bat,  Version 1.01 for Windows XP professional and later
  61. ECHO Return WMI class name for specified WMIC alias, or list all if none specified
  62. ECHO.
  63. ECHO Usage:  WMIALIAS  [ alias ^| /SORT ]
  64. ECHO.
  65. ECHO Where:  alias     is a WMIC alias, e.g. "bios" for the "Win32_BIOS" class
  66. ECHO         /SORT     sort output by WMI class name (default: sort by WMIC alias)
  67. ECHO.
  68. ECHO Notes:  If no alias is specified, all WMIC aliases and their WMI class names
  69. ECHO         will be listed.
  70. ECHO         Listed output is sorted by WMIC alias name by default, or by WMI class
  71. ECHO         name if the /SORT switch is used.
  72. ECHO.
  73. ECHO Written by Rob van der Woude
  74. ECHO https://www.robvanderwoude.com
  75.  
  76. ENDLOCAL
  77. EXIT /B 1
  78.  

page last modified: 2024-04-16; loaded in 0.0055 seconds