找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 28426|回复: 3

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

[复制链接]
发表于 2011-11-18 09:48:49 | 显示全部楼层 |阅读模式
我想在此脚本中添加一项可以获取本机计算机名,烦请各位老师帮忙,非常感谢!
  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.        
  18. Next

  19. For Each oComputerSystemProduct In colComputerSystemProductItems
  20.        
  21.         objFile.writeline("UUID is: " & oComputerSystemProduct.UUID)
  22.         objFile.Writeline()
  23. Next
  24.        
  25. For Each oSMBIOS In colSMBIOSItems
  26.        
  27.         objFile.Writeline("BIOS version is: " & oSMBIOS.SMBIOSBIOSVersion)
  28.         objFile.Writeline("Serial Number is: " & oSMBIOS.SerialNumber)
  29.         objFile.Writeline()
  30. Next
  31.         objFile.Writeline("hostname is: " & hostname)
  32.    
  33. Next

  34. For Each NetworkAdapter in colNetworkAdapterItems  
  35.                     
  36.            If i < 3 Then
  37.          
  38.         objFile.Writeline("NIC " & i & " name is: " & NetworkAdapter.Description)
  39.         objFile.writeline("MAC address is: " & NetworkAdapter.MACAddress)
  40.         objFile.Writeline()

  41.         i = i + 1
  42.        
  43.         End If

  44.   
  45. Next  

  46. wscript.echo "Workstation info dumping is finished!"
复制代码

评分

参与人数 1PB +2 收起 理由
broly + 2 感谢给帖子标题标注[已解决]字样

查看全部评分

发表于 2011-11-18 10:23:58 | 显示全部楼层
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:16 | 显示全部楼层
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
 楼主| 发表于 2011-11-18 10:39:48 | 显示全部楼层
问题已经解决,,谢谢你们~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 07:26 , Processed in 0.022358 second(s), 12 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表