rojo

http://stackoverflow.com/a/16044631/1683264

May 21st, 2013
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.85 KB | None | 0 0
  1. @echo off
  2. setlocal
  3. set prefix=G:\Directory
  4.  
  5.  
  6. :: See "wmic /help" for more information about wmic.
  7.  
  8. :: From the output of "wmic os get name, version /format:list" set "name=os name" and "version=os version" (but stopping if a pipe (a "|" symbol) is encountered)
  9. for /f "usebackq tokens=1,2 delims==|" %%I in (`wmic os get name^,version /format:list`) do 2>NUL set "%%I=%%J"
  10.  
  11. :: From the output of "wmic bios get version /format:list" set "bios=bios version"
  12. for /f "tokens=2 delims==" %%I in ('wmic bios get version /format:list') do set "bios=%%I"
  13.  
  14. :: From the output of "wmic computersystem get model /format:list" set "model=computer model"
  15. for /f "tokens=2 delims==" %%I in ('wmic computersystem get model /format:list') do set "model=%%I"
  16.  
  17.  
  18. :: Append to g:\Directory\%COMPUTERNAME% (where %COMPUTERNAME% is an environment variable on the running workstation)
  19. >>"%prefix%\%COMPUTERNAME%" echo OS Name: %name%
  20. >>"%prefix%\%COMPUTERNAME%" echo OS Version: %version%
  21. >>"%prefix%\%COMPUTERNAME%" echo PC Model: %model%
  22. >>"%prefix%\%COMPUTERNAME%" echo BIOS Version: %bios%
  23.  
  24. :: If an environment variable %PROGRAMFILES(x86)% is defined, this is a 64-bit machine.
  25. if defined PROGRAMFILES(x86) (set arch=X64) else set arch=X86
  26.  
  27. :: If %name% does not equal itself with the string "Windows 8" removed, then this is a Windows 8 machine.
  28. :: See http://www.dostips.com/DtTipsStringManipulation.php for similar examples.
  29. if "%name%" neq "%name:Windows 8=%" (
  30.     set out=%prefix%\Win8Comps.txt
  31. ) else if "%name%" neq "%name:Windows 7=%" (
  32.     set out=%prefix%\Win7Comps.txt
  33. ) else if "%name%" neq "%name:Windows Vista=%" (
  34.     set out=%prefix%\WinVistaComps.txt
  35. ) else if "%name%" neq "%name:Windows XP=%" (
  36.     set out=%prefix%\WinXPComps.txt
  37. )
  38.  
  39. :: Append to G:\Directory\Win8Comps.txt or similar
  40. >>"%out%" echo %COMPUTERNAME% is running %name% in %arch% environment
Add Comment
Please, Sign In to add comment