我最初的问题是我想将VBScript输出到文本文件。它最初是做回声,并打印一个空白文件。我只想打印,打印数据。
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\Users\Tyler\Desktop\dude.txt", True)
MyFile.WriteLine("Name: " & objItem.Name)
MyFile.Close
Next
这是正确的代码。我还希望将多个设备打印到文件中。在下面的示例中,我读取并打印了CPU名称+频率,然后读取GPU信息并将其打印到相同文本文件中。
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\Users\Tyler\Desktop\dude.txt", True)
MyFile.WriteLine("Name: " & objItem.Name)
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_VideoController")
For Each objItem in colItems
MyFile.WriteLine ("Driver Version: " & objItem.DriverVersion)
MyFile.WriteLine ("Name: " & objItem.Name)
MyFile.WriteLine ("Video Processor: " & objItem.VideoProcessor)
Next
MyFile.Close
答案 0 :(得分:0)
你几乎把它当作我的朋友
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
outFile="C:\Users\Tyler\Desktop\test.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)
For Each objItem in colItems
objFile.WriteLine "Name: " & objItem.Name
Next
objFile.Close