如何远程获取MAC 地址和序列号,当前登录用户名

来源:互联网 发布:剑灵最美灵女捏脸数据 编辑:程序博客网 时间:2024/05/21 22:22

 

Dim objexcel,objspread,objlocator,objwmiservice
Dim strcomputer,strusername,strpassword
Dim NetConnectionname,networkname,netwrokMacAddress,loginGID
Dim rownumber


strcomputer=InputBox("please key in computername")
strusername=InputBox("please key in account")
strpassword=InputBox("please key in password")

If ping(strcomputer)=0 then
WScript.Echo("This machine can't be pingable, please check")
wscript.quit
else

set objlocator=CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer ,"\root\cimv2", strUsername ,strPassword)
objWMIService.Security_.ImpersonationLevel = 3


set fso=createobject("scripting.filesystemobject")

if fso.fileExists("c:\mac\mac.xls") then
fso.deletefile("c:\mac\mac.xls")
end if

if fso.folderexists("c:\mac") then
fso.deletefolder("c:\mac")
end if

set myfolder=fso.createfolder("c:\mac")


Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.add
ObjExcel.WorkSheets(1).activate
objExcel.Visible=true
objexcel.Columns(1).ColumnWidth =15.71
objexcel.cells(1,1)=Trim(strcomputer)
objexcel.Columns(2).ColumnWidth =32
objexcel.cells(1,2)="Networkconnection Name"
objexcel.Columns(3).ColumnWidth =40
objexcel.cells(1,3)="Networkcardtype"
objexcel.Columns(4).ColumnWidth =19.86
objexcel.cells(1,4)="NetwrokMacAddress"
objexcel.Columns(5).ColumnWidth =18.42
objexcel.cells(1,5)="Current logining GID"
objexcel.Columns(6).ColumnWidth =12.42
Objexcel.Cells(1,6)="Machine S/N"
rownumber=2


set objcurrentloginname=objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem In objcurrentloginname
    objexcel.cells(2,5)=objitem.UserName
Next

set objserial=objWMIService.ExecQuery("Select * from Win32_BIOS")
For Each objItem In objserial
    objexcel.cells(2,6)=objitem.SerialNumber
Next


set objnetwork=objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID > ''")
For Each objItem In objnetwork
         objexcel.cells(rownumber,2)=objitem.NetConnectionID
         objexcel.cells(rownumber,3)=objitem.Name
         objexcel.cells(rownumber,4)=objitem.MacAddress
         rownumber=rownumber+1
Next

end if


objexcel.activeworkbook.saveas("c:\mac\mac.xls")
objexcel.quit
set objspread=nothing
set objexcel=nothing
set fso=nothing
set myfolder=nothing

Function ping(mycomputer)
Set objPing = objWMIService.ExecQuery("select * from Win32_PingStatus where address = '"_
            & mycomputer & "'")
    For Each objStatus in objPing
        If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
            Ping = 0
        Else
            Ping=-1 
        End If      

    Next  

End Function

 

 

原创粉丝点击