標籤:vbs bat
閑來無事,想把公司域內的電腦統計一些亂七八糟的資訊出來.但是我比較懶,沒有把我公司環境的內容修改成大家都可以用的,僅僅放在這裡給大家一個思路.我對代碼確實是不太懂的,做的東西也都是東拼西湊只為滿足需求就可以,代碼漂亮度就不糾結了.
說明一下,上面的是BAT批處理,下面的是VBS指令碼.因為從WMI拿資料我不知道怎麼在批處理裡面做.在批處理前面一段是用來拿批處理能拿到的資訊,中間調用了VBS來拿WMI裡面的資料.然後在批處理結尾把匯出的TXT文本調整一下.
注意:這隻是我隨手的分享我自己的環境下能用的東西,其他地方並不一定能用,只是給大家一個思路.請有一定代碼能力的人修改後再用到自己的環境.我並不對這段代碼負責.
另外有寫批處理,VBS或POWERSHELL厲害的能教教我嗎...
以下是批處理
@echo offecho 請輸入儲存位置set /p oppath=set t=%time: =0%echo ====================================================>"%oppath%\%computername%-%username%.txt"echo 電腦相關資訊>>"%oppath%\%computername%-%username%.txt"echo.>>"%oppath%\%computername%-%username%.txt"echo 最後一次登陸時間: %date:~,4%年%date:~5,2%月%date:~8,2%日 %t:~0,2%時%t:~3,2%分%t:~6,2%秒>>"%oppath%\%computername%-%username%.txt"echo 電腦名稱: %computername%>>"%oppath%\%computername%-%username%.txt"net config workstation | find "電腦全名" >>"%oppath%\%computername%-%username%.txt"echo 當前登入的電腦名稱: %computername%>>"%oppath%\%computername%-%username%.txt"echo 當前登入的使用者名稱: %username%>>"%oppath%\%computername%-%username%.txt"echo ====================================================>>"%oppath%\%computername%-%username%.txt"echo IP地址相關資訊>>"%oppath%\%computername%-%username%.txt"echo.>>"%oppath%\%computername%-%username%.txt"@echo off>>"%oppath%\%computername%-%username%.txt"ipconfig |find "IPv4">>"%oppath%\%computername%-%username%.txt"@echo off>>"%oppath%\%computername%-%username%.txt"ipconfig |find "網關">>"%oppath%\%computername%-%username%.txt"@echo off>>"%oppath%\%computername%-%username%.txt"ipconfig/all |find "DNS 伺服器">>"%oppath%\%computername%-%username%.txt"@echo off>>"%oppath%\%computername%-%username%.txt"ipconfig/all |find "DHCP 伺服器">>"%oppath%\%computername%-%username%.txt"echo ====================================================>>"%oppath%\%computername%-%username%.txt"echo offcscript %oppath%\script\Get_Information.vbs>>"%oppath%\%computername%-%username%.txt"set Keyword1=Microsoft (R) Windows Script Host Version 5.8set Keyword2=著作權(C) Microsoft Corporation 1996-2001。著作權所有,並保留一切權利。findstr /v /c:"%Keyword1%" %oppath%\%computername%-%username%.txt>%oppath%\%computername%-%username%.tempmove /y %oppath%\%computername%-%username%.temp %oppath%\%computername%-%username%.txtfindstr /v /c:"%Keyword2%" %oppath%\%computername%-%username%.txt>%oppath%\%computername%-%username%.tempmove /y %oppath%\%computername%-%username%.temp %oppath%\%computername%-%username%.txtsysteminfo >>"%oppath%\%computername%-%username%.txt"pause
以下是VBS
Wscript.Echo "電腦硬體資訊" Wscript.Echo strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_BIOS",,48) Wscript.Echo "*電腦品牌" For Each objItem in colItems Wscript.Echo objItem.ManufacturerWscript.Echo "--------------------------"Wscript.Echo Wscript.Echo "*序號" Wscript.Echo objItem.SerialNumberNext Wscript.Echo "--------------------------"Wscript.Echo strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colChassis = objWMIService.ExecQuery _ ("Select * from Win32_SystemEnclosure") Wscript.Echo "*電腦類型" For Each objChassis in colChassis For Each strChassisType in objChassis.ChassisTypes Select Case strChassisType Case 1 Wscript.Echo "Other" Case 2 Wscript.Echo "Unknown" Case 3 Wscript.Echo "Desktop" Case 4 Wscript.Echo "Low Profile Desktop" Case 5 Wscript.Echo "Pizza Box" Case 6 Wscript.Echo "Mini Tower" Case 7 Wscript.Echo "Tower" Case 8 Wscript.Echo "Portable" Case 9 Wscript.Echo "Laptop" Case 10 Wscript.Echo "Notebook" Case 11 Wscript.Echo "Handheld" Case 12 Wscript.Echo "Docking Station" Case 13 Wscript.Echo "All-in-One" Case 14 Wscript.Echo "Sub-Notebook" Case 15 Wscript.Echo "Space Saving" Case 16 Wscript.Echo "Lunch Box" Case 17 Wscript.Echo "Main System Chassis" Case 18 Wscript.Echo "Expansion Chassis" Case 19 Wscript.Echo "Sub-Chassis" Case 20 Wscript.Echo "Bus Expansion Chassis" Case 21 Wscript.Echo "Peripheral Chassis" Case 22 Wscript.Echo "Storage Chassis" Case 23 Wscript.Echo "Rack Mount Chassis" Case 24 Wscript.Echo "Sealed-Case PC" Case Else Wscript.Echo "Unknown" End Select NextNext Wscript.Echo "--------------------------"nicnum=1Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_Processor",,48) For Each objItem in colItems Wscript.Echo Wscript.Echo "*CPU型號" Wscript.Echo objItem.NameNext Wscript.Echo "--------------------------"On Error Resume Next dim MemorySet objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * from Win32_PhysicalMemory") For Each objItem in colItems Memory = objItem.Capacity/1024/1024/1024 Wscript.Echo Wscript.Echo "*記憶體容量" Wscript.Echo("Memory=" & Memory & "G")Next Wscript.Echo "--------------------------" Wscript.Echo Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_NetworkAdapterConfiguration",,48) For Each objItem in colItems If isNull(objItem.IPAddress) Then ‘Wscript.Echo "IPAddress: " Else Wscript.Echo "*網卡"&nicnumWscript.Echo "網卡名稱:" &objItem.caption Wscript.Echo "IPV4:" & Join(objItem.IPAddress,chr(10)&"IPV6:")Wscript.Echo "MAC地址:" &objItem.macAddress&chr(10)nicnum=nicnum+1 End IfNext Wscript.Echo "--------------------------"
本文出自 “彪鍋” 部落格,請務必保留此出處http://38088444.blog.51cto.com/7547614/1665066
指令碼-收集電腦資訊