Board logo

标题: [转贴] [ZT]实用的域登录脚本实例 [打印本页]

作者: Batcher    时间: 2009-3-3 17:11     标题: [ZT]实用的域登录脚本实例

原文地址:http://hi.baidu.com/longerwg/blo ... 5b301ab31bbac9.html
  1. Dim WshShell, fso
  2. Const ForReading = 1, ForWriting = 2
  3. Set WshShell = WScript.CreateObject("WScript.Shell")
  4. Set fso = CreateObject("Scripting.FileSystemObject")
  5. On Error Resume Next
  6. '清理系统垃圾文件
  7. WshShell.Run "cmd /q/c for /d %%i in (%SystemRoot%\$Nt*) do rd /s/q ""%%i""",0
  8. WshShell.Run "cmd /q/c for /d %%i in (%SystemRoot%\$hf_mig$\*) do rd /s/q ""%%i""",0
  9. WshShell.Run "cmd /q/c for %%i in (%SystemRoot%\*.log) do del/f/q ""%%i""",0
  10. WshShell.Run "cmd /q/c for %%i in (%SystemRoot%\*.tmp) do del/f/q ""%%i""",0
  11. WshShell.Run "cmd /q/c for /d %%i in (%TEMP%\*) do rd /s/q ""%%i""",0
  12. WshShell.Run "cmd /q/c for %%i in (%TEMP%\*) do del/f/q ""%%i""",0
  13. '连接共享的网络打印机
  14. Set WshNetwork = WScript.CreateObject("WScript.Network")
  15. a = WshNetwork.UserName '获取登录用户名称
  16. b = WshNetwork.ComputerName '获取计算机名称
  17. WshNetwork.AddWindowsPrinterConnection "\\打印服务器\共享打印机名"
  18. '获取IP地址
  19. strComputer = "."
  20. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  21. Set IPConfigSet = objWMIService.ExecQuery _
  22. ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
  23. For Each IPConfig in IPConfigSet
  24. If Not IsNull(IPConfig.IPAddress) Then
  25. For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
  26. j = IPConfig.Index(i)
  27. k = IPConfig.IPAddress(i)
  28. If Len(k) > 0 Then Exit For
  29. Next
  30. End If
  31. Next
  32. '获取网卡MAC地址
  33. Set colNetworkAdapters = objWMIService.InstancesOf("Win32_NetworkAdapter")
  34. For Each objNetworkAdapter In colNetworkAdapters
  35. If j = objNetworkAdapter.Index Then c = Replace(objNetworkAdapter.MACAddress,":","-")
  36. Next
  37. '获取CPU频率
  38. Set colProcessors = objWMIService.InstancesOf("Win32_Processor")
  39. For Each objProcessor In colProcessors
  40. t1 = objProcessor.Name
  41. t1 = t1 & " " & objProcessor.CurrentClockSpeed & " MHz"
  42. If Len(Trim(t1)) > 0 Then Exit For
  43. Next
  44. '获取内存容量
  45. Set colLogicalMemoryConfigurations = objWMIService.InstancesOf("Win32_LogicalMemoryConfiguration")
  46. For Each objLogicalMemoryConfiguration In colLogicalMemoryConfigurations
  47. t2 = CInt(objLogicalMemoryConfiguration.TotalPhysicalMemory / 1024) & " MB"
  48. Next
  49. '获取获取第一硬盘型号
  50. Set colDiskDrives = objWMIService.ExecQuery _
  51. ("Select * from Win32_DiskDrive where Index=0")
  52. For each objDiskDrive in colDiskDrives
  53. t3 = objDiskDrive.Model
  54. Next
  55. '获取获取第二硬盘型号
  56. Set colDiskDrives = objWMIService.ExecQuery _
  57. ("Select * from Win32_DiskDrive where Index=1")
  58. For each objDiskDrive in colDiskDrives
  59. t4 = objDiskDrive.Model
  60. Next
  61. '获取获取第三硬盘型号
  62. Set colDiskDrives = objWMIService.ExecQuery _
  63. ("Select * from Win32_DiskDrive where Index=2")
  64. For each objDiskDrive in colDiskDrives
  65. t5 = objDiskDrive.Model
  66. Next
  67. '获取获取第四硬盘型号
  68. Set colDiskDrives = objWMIService.ExecQuery _
  69. ("Select * from Win32_DiskDrive where Index=3")
  70. For each objDiskDrive in colDiskDrives
  71. t6 = objDiskDrive.Model
  72. Next
  73. '获取获取第一光驱型号
  74. Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive where SCSITargetId=0")
  75. For Each objItem in colItems
  76. t7 = objItem.Name
  77. Next
  78. '获取获取其它光驱型号
  79. Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive where SCSITargetId<>0")
  80. For Each objItem in colItems
  81. t8 = objItem.Name
  82. Next
  83. '获取获取显卡型号
  84. Set colItems = objWMIService.ExecQuery("Select * from Win32_DisplayControllerConfiguration")
  85. For Each objItem in colItems
  86. t9 = objItem.Name
  87. Next
  88. '生成记录文件
  89. MyFile = "\\服务器名\配置文件存放地址\" & Mid(k,13) & "-" & b & ".csv"
  90. all = a & "," & b & "," & k & "," & c & "," & t1 & "," & t2 & "," & t3 & "," & t4 & "," & t5 & "," & t6 & "," & t7 & "," & t8 & "," & t9
  91. Set f = fso.OpenTextFile(MyFile, ForWriting, True) '打开文件
  92. f.WriteLine(all)
  93. f.Close
复制代码





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