windows batch-file wmic

windows - Texto ilegible en script por lotes para el comando wmic



batch-file (1)

Su problema es que SYSTEMINFO produce salida ANSII (como la mayoría de los comandos), pero WMIC produce salida Unicode. Los dos no se mezclan bien.

A continuación hay tres soluciones que producen todas las salidas ANSII.

1) Canalice la salida WMIC a MÁS

MÁS convierte Unicode a ANSII. También canalizo ese resultado a FINDSTR para eliminar líneas en blanco. El único problema con esta solución es que una peculiaridad con las conversiones hace que la salida WMIC tenga un retorno de carro adicional al final de cada línea ( <CR><CR><LF> lugar de <CR><LF> )

@echo OFF >test1.txt ( echo Manufacturer Information: systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" echo( echo CPU Information: wmic cpu get Name /Format:list | more | findstr . wmic computersystem get NumberofProcessors /Format:list | more | findstr . echo( echo NIC Information: wmic nicconfig where IPEnabled=TRUE get ipaddress, macaddress,defaultipgateway /format:list | more | findstr . )


------------------------------

Las soluciones restantes están formateadas correctamente, sin ningún <CR> adicional

2) Escriba la salida WMIC en un archivo temporal, seguido de TYPE

El archivo temporal está en formato Unicode y TYPE convierte correctamente el Unicode a ANSII. Todavía canalizo el resultado a FINDSTR para eliminar líneas en blanco.

@echo OFF >test2.txt ( echo Manufacturer Information: systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" echo( echo CPU Information: call :wmic cpu get Name /Format:list call :wmic computersystem get NumberofProcessors /Format:list echo( echo NIC Information: call :wmic nicconfig where IPEnabled=TRUE get ipaddress, macaddress,defaultipgateway /format:list ) exit /b :wmic wmic %* >test.tmp type test.tmp | findstr . del test.tmp exit /b


3) Ejecute WMIC a través de dos bucles FOR / F.

El primer FOR / F convierte la salida WMIC a ANSII, pero tiene el <CR> adicional al final de cada línea. El segundo FOR / F elimina el <CR> final no deseado. FOR / F elimina automáticamente las líneas en blanco.

@echo OFF >test3.txt ( echo Manufacturer Information: systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" echo( echo CPU Information: call :wmic cpu get Name /Format:list call :wmic computersystem get NumberofProcessors /Format:list echo( echo NIC Information: call :wmic nicconfig where IPEnabled=TRUE get ipaddress, macaddress,defaultipgateway /format:list ) exit /b :wmic for /f "delims=" %%A in (''"wmic %*"'') do for /f "delims=" %%B in ("%%A") do echo %%B exit /b

Estoy tratando de ejecutar el script por lotes para adquirir la información básica de la computadora como CPU, RAM y tarjeta de red activa. Aquí está mi código

@Echo OFF set newline=^& echo. echo Manufacturer Information> test1.txt systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" >>test1.txt echo CPU Information:>> test1.txt wmic cpu get Name /Format:list >> test1.txt echo %newline%Process Information:>> test1.txt wmic computersystem get NumberofProcessors /Format:list >> test1.txt echo %newline%NIC Information:>> test1.txt wmic nicconfig where "IPEnabled=TRUE" get ipaddress, macaddress,defaultipgateway /format:list >>test1.txt

La apariencia se ve:

Información del fabricante Nombre del host: Nombre del sistema operativo DK-IT:
Modelo de sistema de idioma único de Microsoft Windows 8.1:
Inspiron 7537 Tipo de sistema: PC basada en x64 Memoria física total: 6.043 MB Información de la CPU:

N a m e = I n t e l ( R ) C o r e ( T M ) i 5 - 4 2 0 0 U C P U @ 1 . 6 0 G H z Process Information: N u m b e r O f P r o c e s s o r s = 1 NIC Information: D e f a u l t I P G a t e w a y = { " 1 0 . 5 . 1 . 1 " } I P A d d r e s s = { " 1 0 . 5 . 4 . 5 4 " , " f e 8 0 : : 1 0 e b : 1 d

2 d: 2 0 8 8: 8 ba 1 "} Dirección MACA = 0 C: 8 B: FD: 9 C: 8 0: 4 7

D e f a u l t I P G a t e w a y = I P A d d r e s s = { " 1 9 2 . 1 6 8 . 1 9 9 . 1 " } M A C A d d r e s s = 0 0 : 5 0 : 5 6 :

C 0: 0 0: 0 1

Dirección IPG predeterminada = Dirección IPA = {"1 9 2. 1 6 8. 1 9 0. 1", "fe 8 0:: 6 4 b 2: 2 aaa: ef 6 4: fa 9 a"} Dirección MACA = 0 0: 5 0: 5 6: C 0: 0 0: 0 8

¿Alguien puede ayudar a modificar la vista de salida del archivo por lotes?