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. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  3. IF NOT  "%~2"==""           GOTO Syntax
  4. IF      "%~1"=="/?"         GOTO Syntax
  5. WMIC /?  >NUL  2>&1   ||    GOTO Syntax
  6.  
  7. :: No command line argument: list all aliases and their true class names, sorted by alias
  8. IF "%~1"=="" (
  9. 	"%~f0" /SORT | SORT
  10. 	GOTO:EOF
  11. )
  12.  
  13. IF /I "%~1"=="/SORT" (
  14. 	REM List all aliases and their true class names
  15. 	Call :List
  16. ) ELSE (
  17. 	REM Show specified alias and its true class name
  18. 	CALL :List %1
  19. )
  20.  
  21. GOTO:EOF
  22.  
  23.  
  24. :List
  25. SETLOCAL ENABLEDELAYEDEXPANSION
  26. (ECHO ALIAS:                      WMI CLASS NAME:) 1>&2
  27. (ECHO.======                      ===============) 1>&2
  28. FOR /F "skip=1 tokens=1,5" %%A IN ('WMIC ALIAS %1 Get FriendlyName^,Target') DO (
  29. 	REM Append 20 spaces to alias
  30. 	SET Output=%%A                    
  31. 	REM Chop alias plus spaces at 20 characters
  32. 	SET Output=!Output:~0,20!
  33. 	REM Append class name
  34. 	SET Output=!Output!        %%B
  35. 	ECHO.!Output!
  36. )
  37. ENDLOCAL
  38. GOTO:EOF
  39.  
  40.  
  41. :Syntax
  42. ECHO.
  43. ECHO WMIAlias.bat,  Version 1.00 for Windows XP professional and later
  44. ECHO Return the class name for the specified WMIC alias, or all if none specified
  45. ECHO.
  46. ECHO Usage:  WMIALIAS  [ alias ]
  47. ECHO.
  48. ECHO Where:  alias     is a WMIC alias, e.g. "bios" for the "Win32_BIOS" class
  49. ECHO.
  50. ECHO Note:   If no alias is specified, all WMIC aliases and their class names will
  51. ECHO         be listed, sorted by alias name.
  52.  
  53. IF NOT "%OS%"=="Windows_NT" GOTO :SkippedIfNotNT
  54. ECHO         To sort the output by class name, use the following command:
  55. ECHO         WMIALIAS  ^|  SORT  /+20
  56. :SkippedIfNotNT
  57.  
  58. ECHO.
  59. ECHO Written by Rob van der Woude
  60. ECHO http://www.robvanderwoude.com
  61.  
  62. IF "%OS%"=="Windows_NT" EXIT /B 1
  63.  

page last uploaded: 2017-08-21, 14:26