Board logo

标题: [转贴] WMI在VBS、BAT中的几个应用实例 [打印本页]

作者: lixiaodaoaaa    时间: 2008-12-17 10:36     标题: WMI在VBS、BAT中的几个应用实例

'部分转载
1、枚举进程

  1. st = "."
  2. set objp = GetObject("winmgmts:\\" & st)
  3. set objs = objp.instancesof("Win32_Process")
  4. for each ps in objs
  5. msgbox ps.name&vbcrlf&ps.processid&vbcrlf&ps.commandline
  6. next
复制代码

  1. @echo off
  2. rem 输出到指定文本
  3. wmic /output:D:\a.txt process get name,processid,commandline
  4. pause
复制代码

2、获取计算机名


  1. st = "."
  2. set objp = GetObject("winmgmts:\\" & st & "\root\cimv2")
  3. set objs = objp.execquery("select * from Win32_computersystem")
  4. for each ps in objs
  5. msgbox ps.name
  6. next
复制代码


  1. @echo off
  2. wmic computersystem get name
  3. pause
复制代码

3、检测启动项
  1. @echo off
  2. wmic startup get caption,command
  3. pause
复制代码

4、检查共享
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  3. Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
  4. For each objShare in colShares
  5. Wscript.Echo "Name: " & objShare.Name
  6. Wscript.Echo "Path: " & objShare.Path
  7. Wscript.Echo "Type: " & objShare.Type
  8. Next
复制代码

  1. @echo off
  2. wmic share get name,path,type
  3. pause
复制代码

5、检测磁盘系统
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  3. Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where
  4. DriveType = 3")
  5. For Each objDisk in colDisks
  6. Wscript.Echo "Disk drive: "& objDisk.DeviceID & " -- " & objDisk.FileSystem
  7. Next
复制代码


  1. @echo off
  2. wmic logicaldisk get deviceid,filesystem
  3. pause
复制代码

6、检测CPU
  1. Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  2. Set colCPUs = objWMIService.InstancesOf("Win32_Processor")
  3. Set colCaches = objWMIService.InstancesOf("Win32_CacheMemory")
  4. For Each objCPU In colCPUs
  5. WScript.Echo "CPU设备:" & objCPU.DeviceID
  6. WScript.Echo "CPU名称: " & ltrim(objCPU.Name)
  7. WScript.Echo "接口规格:" & objCPU.SocketDesignation
  8. WScript.Echo "CPU电压:" & objCPU.CurrentVoltage / 10 & "V"
  9. WScript.Echo "主频速度:" & objCPU.CurrentClockSpeed & "MHZ"
  10. WScript.Echo "外频速度:" & objCPU.ExtClock & "MHZ"
  11. WScript.Echo "CPU缓存:"
  12.     For Each objCache In colCaches
  13.         Select Case objCache.Level
  14.         case 3
  15.             WScript.Echo chr(9) & "一级缓存大小(数据缓存+跟踪缓存):" &
  16. objCache.MaxCacheSize & "KB"
  17.         case 4
  18.             WScript.Echo chr(9) & "二级缓存大小:" & objCache.MaxCacheSize &
  19. "KB"
  20.         case 5
  21.             WScript.Echo chr(9) & "三级缓存大小:" & objCache.MaxCacheSize &
  22. "KB"
  23.         End Select
  24.     Next
  25. Next
复制代码

7、检测GUEST状态
  1. Set objNetwork = CreateObject("Wscript.Network")
  2. strComputer = objNetwork.ComputerName
  3. Set objUser = GetObject("WinNT://" & strComputer & "/Guest")
  4. If objUser.AccountDisabled Then
  5. Wscript.Echo "The Guest account is disabled."
  6. Else
  7. Wscript.Echo "The Guest account is enabled."
  8. End If
复制代码

8、检测电脑机型

  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:" _
  3. & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  4. Set colChassis = objWMIService.ExecQuery _
  5. ("Select * from Win32_SystemEnclosure")
  6. For Each objChassis in colChassis
  7. For Each strChassisType in objChassis.ChassisTypes
  8. Select Case strChassisType
  9. Case 1
  10. Wscript.Echo "Other"
  11. Case 2
  12. Wscript.Echo "Unknown"
  13. Case 3
  14. Wscript.Echo "Desktop"
  15. Case 4
  16. Wscript.Echo "Low Profile Desktop"
  17. Case 5
  18. Wscript.Echo "Pizza Box"
  19. Case 6
  20. Wscript.Echo "Mini Tower"
  21. Case 7
  22. Wscript.Echo "Tower"
  23. Case 8
  24. Wscript.Echo "Portable"
  25. Case 9
  26. Wscript.Echo "Laptop"
  27. Case 10
  28. Wscript.Echo "Notebook"
  29. Case 11
  30. Wscript.Echo "Handheld"
  31. Case 12
  32. Wscript.Echo "Docking Station"
  33. Case 13
  34. Wscript.Echo "All-in-One"
  35. Case 14
  36. Wscript.Echo "Sub-Notebook"
  37. Case 15
  38. Wscript.Echo "Space Saving"
  39. Case 16
  40. Wscript.Echo "Lunch Box"
  41. Case 17
  42. Wscript.Echo "Main System Chassis"
  43. Case 18
  44. Wscript.Echo "Expansion Chassis"
  45. Case 19
  46. Wscript.Echo "Sub-Chassis"
  47. Case 20
  48. Wscript.Echo "Bus Expansion Chassis"
  49. Case 21
  50. Wscript.Echo "Peripheral Chassis"
  51. Case 22
  52. Wscript.Echo "Storage Chassis"
  53. Case 23
  54. Wscript.Echo "Rack Mount Chassis"
  55. Case 24
  56. Wscript.Echo "Sealed-Case PC"
  57. Case Else
  58. Wscript.Echo "Unknown"
  59. End Select
  60. Next
  61. Next
复制代码

  1. @echo off
  2. wmic SystemEnclosure get ChassisTypes
  3. pause
复制代码

9、检测接入系统的USB设备
  1. st = "."
  2. set objp = getobject("winmgmts:\\"&st&"\root\cimv2")
  3. set objs = objp.execquery("select * from Win32_USBControllerDevice")
  4. for each p in objs
  5. msgbox p.Dependent
  6. next
复制代码







[ 本帖最后由 lixiaodaoaaa 于 2008-12-17 10:43 编辑 ]
作者: qlcom    时间: 2008-12-18 00:58

楼主说的都是显示信息类的,能不能修改对应参数的值啊?每次我用set命令修改时都不行
作者: jackmux    时间: 2012-5-26 16:58

如何用?:dizzy::dizzy:
作者: cjiabing    时间: 2012-5-29 20:10

回复 3# jackmux


    你试试看~




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