Board logo

标题: [问题求助] [已解决]VBS如何获取本机计算机名? [打印本页]

作者: xtdawei    时间: 2011-11-18 09:48     标题: [已解决]VBS如何获取本机计算机名?

我想在此脚本中添加一项可以获取本机计算机名,烦请各位老师帮忙,非常感谢!
  1. dim objFileSys
  2. dim objFile
  3. i = 1
  4. set objFileSys = wscript.Createobject("Scripting.FileSystemObject")
  5. set objFile = objFileSys.createTextFile("WKS_Info.txt",True)
  6. strComputer ="."
  7. Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
  8. Set colComputerSystemItems = oWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem",,48)
  9. Set colComputerSystemProductItems = oWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystemProduct",,48)
  10. Set colSMBIOSItems = oWMIService.ExecQuery( "Select * from Win32_BIOS where PrimaryBIOS = true", , 48 )
  11. Set colNetworkAdapterItems = oWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = 1",,48)
  12. ' On Error Resume Next
  13. For Each oComputerSystem In colComputerSystemItems
  14. objFile.Writeline("Made by: " & oComputerSystem.Manufacturer)
  15. objFile.Writeline("Model is: " & oComputerSystem.Model)
  16. objFile.Writeline()
  17. Next
  18. For Each oComputerSystemProduct In colComputerSystemProductItems
  19. objFile.writeline("UUID is: " & oComputerSystemProduct.UUID)
  20. objFile.Writeline()
  21. Next
  22. For Each oSMBIOS In colSMBIOSItems
  23. objFile.Writeline("BIOS version is: " & oSMBIOS.SMBIOSBIOSVersion)
  24. objFile.Writeline("Serial Number is: " & oSMBIOS.SerialNumber)
  25. objFile.Writeline()
  26. Next
  27.         objFile.Writeline("hostname is: " & hostname)
  28.    
  29. Next
  30. For Each NetworkAdapter in colNetworkAdapterItems  
  31.      
  32.     If i < 3 Then
  33.   
  34. objFile.Writeline("NIC " & i & " name is: " & NetworkAdapter.Description)
  35. objFile.writeline("MAC address is: " & NetworkAdapter.MACAddress)
  36. objFile.Writeline()
  37. i = i + 1
  38. End If
  39.   
  40. Next  
  41. wscript.echo "Workstation info dumping is finished!"
复制代码

作者: broly    时间: 2011-11-18 10:23

dim objFileSys
dim objFile
i = 1

set objFileSys = wscript.Createobject("Scripting.FileSystemObject")
set objFile = objFileSys.createTextFile("WKS_Info.txt",True)



strComputer ="."

Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colComputerSystemItems = oWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem",,48)
Set colComputerSystemProductItems = oWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystemProduct",,48)
Set colSMBIOSItems = oWMIService.ExecQuery( "Select * from Win32_BIOS where PrimaryBIOS = true", , 48 )
Set colNetworkAdapterItems = oWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = 1",,48)
set hostname = hostname

' On Error Resume Next
For Each oComputerSystem In colComputerSystemItems

        objFile.Writeline("Name is: " & oComputerSystem.Name)
        objFile.Writeline("Made by: " & oComputerSystem.Manufacturer)
        objFile.Writeline("Model is: " & oComputerSystem.Model)
        objFile.Writeline()
        
Next

For Each oComputerSystemProduct In colComputerSystemProductItems
        
        objFile.writeline("UUID is: " & oComputerSystemProduct.UUID)
        objFile.Writeline()
Next
        
For Each oSMBIOS In colSMBIOSItems
        
        objFile.Writeline("BIOS version is: " & oSMBIOS.SMBIOSBIOSVersion)
        objFile.Writeline("Serial Number is: " & oSMBIOS.SerialNumber)
        objFile.Writeline()
Next
        objFile.Writeline("hostname is: " & hostname)
   
Next

For Each NetworkAdapter in colNetworkAdapterItems  
                    
           If i < 3 Then
         
        objFile.Writeline("NIC " & i & " name is: " & NetworkAdapter.Description)
        objFile.writeline("MAC address is: " & NetworkAdapter.MACAddress)
        objFile.Writeline()

        i = i + 1
        
        End If

  
Next  

wscript.echo "Workstation info dumping is finished!"
作者: 小爪冰凉君    时间: 2011-11-18 10:38

strComputer = "."  
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")  
Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")  
For Each objComputer in colComputers  
Wscript.Echo objComputer.Name
Next
作者: xtdawei    时间: 2011-11-18 10:39

问题已经解决,,谢谢你们~~




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2