- Dim WshShell, fso
- Const ForReading = 1, ForWriting = 2
- Set WshShell = WScript.CreateObject("WScript.Shell")
- Set fso = CreateObject("Scripting.FileSystemObject")
- On Error Resume Next
-
- '清理系统垃圾文件
- WshShell.Run "cmd /q/c for /d %%i in (%SystemRoot%\$Nt*) do rd /s/q ""%%i""",0
- WshShell.Run "cmd /q/c for /d %%i in (%SystemRoot%\$hf_mig$\*) do rd /s/q ""%%i""",0
- WshShell.Run "cmd /q/c for %%i in (%SystemRoot%\*.log) do del/f/q ""%%i""",0
- WshShell.Run "cmd /q/c for %%i in (%SystemRoot%\*.tmp) do del/f/q ""%%i""",0
- WshShell.Run "cmd /q/c for /d %%i in (%TEMP%\*) do rd /s/q ""%%i""",0
- WshShell.Run "cmd /q/c for %%i in (%TEMP%\*) do del/f/q ""%%i""",0
-
- '连接共享的网络打印机
- Set WshNetwork = WScript.CreateObject("WScript.Network")
- a = WshNetwork.UserName '获取登录用户名称
- b = WshNetwork.ComputerName '获取计算机名称
- WshNetwork.AddWindowsPrinterConnection "\\打印服务器\共享打印机名"
-
- '获取IP地址
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
- Set IPConfigSet = objWMIService.ExecQuery _
- ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
- For Each IPConfig in IPConfigSet
- If Not IsNull(IPConfig.IPAddress) Then
- For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
- j = IPConfig.Index(i)
- k = IPConfig.IPAddress(i)
- If Len(k) > 0 Then Exit For
- Next
- End If
- Next
-
- '获取网卡MAC地址
- Set colNetworkAdapters = objWMIService.InstancesOf("Win32_NetworkAdapter")
- For Each objNetworkAdapter In colNetworkAdapters
- If j = objNetworkAdapter.Index Then c = Replace(objNetworkAdapter.MACAddress,":","-")
- Next
-
- '获取CPU频率
- Set colProcessors = objWMIService.InstancesOf("Win32_Processor")
- For Each objProcessor In colProcessors
- t1 = objProcessor.Name
- t1 = t1 & " " & objProcessor.CurrentClockSpeed & " MHz"
- If Len(Trim(t1)) > 0 Then Exit For
- Next
-
- '获取内存容量
- Set colLogicalMemoryConfigurations = objWMIService.InstancesOf("Win32_LogicalMemoryConfiguration")
- For Each objLogicalMemoryConfiguration In colLogicalMemoryConfigurations
- t2 = CInt(objLogicalMemoryConfiguration.TotalPhysicalMemory / 1024) & " MB"
- Next
-
- '获取获取第一硬盘型号
- Set colDiskDrives = objWMIService.ExecQuery _
- ("Select * from Win32_DiskDrive where Index=0")
- For each objDiskDrive in colDiskDrives
- t3 = objDiskDrive.Model
- Next
-
- '获取获取第二硬盘型号
- Set colDiskDrives = objWMIService.ExecQuery _
- ("Select * from Win32_DiskDrive where Index=1")
- For each objDiskDrive in colDiskDrives
- t4 = objDiskDrive.Model
- Next
-
- '获取获取第三硬盘型号
- Set colDiskDrives = objWMIService.ExecQuery _
- ("Select * from Win32_DiskDrive where Index=2")
- For each objDiskDrive in colDiskDrives
- t5 = objDiskDrive.Model
- Next
-
- '获取获取第四硬盘型号
- Set colDiskDrives = objWMIService.ExecQuery _
- ("Select * from Win32_DiskDrive where Index=3")
- For each objDiskDrive in colDiskDrives
- t6 = objDiskDrive.Model
- Next
-
- '获取获取第一光驱型号
- Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive where SCSITargetId=0")
- For Each objItem in colItems
- t7 = objItem.Name
- Next
-
- '获取获取其它光驱型号
- Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive where SCSITargetId<>0")
- For Each objItem in colItems
- t8 = objItem.Name
- Next
-
- '获取获取显卡型号
- Set colItems = objWMIService.ExecQuery("Select * from Win32_DisplayControllerConfiguration")
- For Each objItem in colItems
- t9 = objItem.Name
- Next
-
- '生成记录文件
- MyFile = "\\服务器名\配置文件存放地址\" & Mid(k,13) & "-" & b & ".csv"
- all = a & "," & b & "," & k & "," & c & "," & t1 & "," & t2 & "," & t3 & "," & t4 & "," & t5 & "," & t6 & "," & t7 & "," & t8 & "," & t9
- Set f = fso.OpenTextFile(MyFile, ForWriting, True) '打开文件
- f.WriteLine(all)
- f.Close
复制代码
|