請問各位先進,底下指令把結果存成txt檔,但是輸出後wmic 出來的資訊會變成全形 且中間都會多一個空格,請問有什麼解決方法呢?感激不盡
cls
echo 硬體資訊 >>C:\OA30\info.txt
wmic baseboard get product,Manufacturer,version,serialnumber>>C:\OA30\info.txt
wmic memorychip get capacity,manufacturer,devicelocator>>C:\OA30\info.txt
wmic cpu list brief>>C:\OA30\info.txt
wmic diskdrive get caption,size,interfacetype>>C:\OA30\info.txt
The WMIC tool is deprecated in Windows 10, version 21H1 and the 21H1 semi-annual channel release of Windows Server.
WMIC
輸出主要是使用 UTF-16
編碼。 不過使用 /APPEND:"path\to\file" /LOCALE:ms_409
能變動其存檔的編碼模式。
(另, 能用 pipe 轉給 more
等 命令/程式 處理其 UTF-16
編碼字串。 詳情看這。)
cls
@rem ## Setup-variables;
set "myBP=C:\OA30" &@::rem ## Base-Path;
set "myFN=info.txt" &@::rem ## File-Name;
@rem ## "/LOCALE:ms_404" for "zh-TW";
set "myGS= /APPEND:"%myBP%\%myFN%" /LOCALE:ms_404" &@::rem ## wmic-global-switches;
if not exist "%myBP%" mkdir "%myBP%"
@rem ##
>>"%myBP%\%myFN%" echo 硬體資訊
wmic %myGS% baseboard get product,Manufacturer,version,serialnumber
wmic %myGS% memorychip get capacity,manufacturer,devicelocator
wmic %myGS% cpu list brief
wmic %myGS% diskdrive get caption,size,interfacetype
@rem ##
@echo off &@::rem ## Done;
echo File[%myBP%\%myFN%]:
type "%myBP%\%myFN%"
其他參考:
P.s. &@::rem
只是個人習慣的非正規行尾註解語法。
Powershell大法
把底下存成info.ps1
在Powershell輸入ps1的儲存路徑(例:cd C:\Users\XXX\Desktop)後輸入
Set-ExecutionPolicy RemoteSigned
Import-Module ps2exe
ps2exe -inputFile info.ps1 -outputFile info.exe
就會變成info.exe
$filePath = "C:\OA30\info.txt"
# 添加標題和系統時間
"=== 硬體資訊 ===" | Out-File -FilePath $filePath -Append
"`n" | Out-File -FilePath $filePath -Append
"收集時間:$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" | Out-File -FilePath $filePath -Append
"`n" | Out-File -FilePath $filePath -Append
# 取得主機板資訊
"主機板資訊:" | Out-File -FilePath $filePath -Append
$baseboardInfo = Get-WmiObject Win32_BaseBoard | Select-Object Product, Manufacturer, Version, SerialNumber
$baseboardInfo | Format-Table -AutoSize | Out-File -FilePath $filePath -Append
"`n" | Out-File -FilePath $filePath -Append
# 取得記憶體資訊
"記憶體資訊:" | Out-File -FilePath $filePath -Append
$memoryInfo = Get-WmiObject Win32_PhysicalMemory | Select-Object Capacity, Manufacturer, DeviceLocator, PartNumber, Speed
$memoryInfo | Format-Table -AutoSize | Out-File -FilePath $filePath -Append
"`n" | Out-File -FilePath $filePath -Append
# 取得處理器資訊
"處理器資訊:" | Out-File -FilePath $filePath -Append
$processorInfo = Get-WmiObject Win32_Processor | Select-Object Name, Manufacturer, Caption, MaxClockSpeed, NumberOfCores, NumberOfLogicalProcessors
$processorInfo | Format-Table -AutoSize | Out-File -FilePath $filePath -Append
"`n" | Out-File -FilePath $filePath -Append
# 取得硬碟資訊
"硬碟資訊:" | Out-File -FilePath $filePath -Append
$diskInfo = Get-WmiObject Win32_DiskDrive | Select-Object Caption, Size, InterfaceType, MediaType, Model
$diskInfo | Format-Table -AutoSize | Out-File -FilePath $filePath -Append
info.exe執行結果如下