Vbscript Vbs从txt文件读取并返回数据

Vbscript Vbs从txt文件读取并返回数据,vbscript,text-files,Vbscript,Text Files,我需要一个脚本,从一个txt文件(一个计算机列表)读取,并返回多少时间之前,我们有夏时制开始 以下是我目前的脚本: strComputer = "C:\temp\computerlist.txt" For Each computer in strComputer For Each objItem in colItems Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

我需要一个脚本,从一个txt文件(一个计算机列表)读取,并返回多少时间之前,我们有夏时制开始

以下是我目前的脚本:

strComputer = "C:\temp\computerlist.txt"

For Each computer in strComputer

For Each objItem in colItems
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime")
    strTime = objItem.Hour & ":" & objItem.Minute & ":" & objItem.Second
    dtmTime = CDate(strTime)
    Wscript.Echo FormatDateTime(dtmTime, vbFormatLongTime)
Next
Next

DayLightSavingTimes=CDate("21/10/2013 00:00:00")


wscript.echo("It is " & DateDiff("m", Now(), DayLightSavingTimes) & " Months to the DayLightSavingTimes!")
wscript.echo("It is " &  DateDiff("d", Now(), DayLightSavingTimes) & " days to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("h", Now(), DayLightSavingTimes) & " hours to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("n", Now(), DayLightSavingTimes) & " Minutes to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("s", Now(), DayLightSavingTimes) & " seconds to the DayLightSavingTimes!")
当我在一台计算机上运行此功能时,它可以工作:

strComputer = "MyComputer"
WScript.Echo "Running Against Remote Computer Named: " & strComputer

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime")

For Each objItem in colItems
    strTime = objItem.Hour & ":" & objItem.Minute & ":" & objItem.Second
    dtmTime = CDate(strTime)
    Wscript.Echo FormatDateTime(dtmTime, vbFormatLongTime)
Next


DayLightSavingTimes=CDate("21/10/2013 00:00:00")


wscript.echo("It is " & DateDiff("m", Now(), DayLightSavingTimes) & " Months to the DayLightSavingTimes!")
wscript.echo("It is " &  DateDiff("d", Now(), DayLightSavingTimes) & " days to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("h", Now(), DayLightSavingTimes) & " hours to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("n", Now(), DayLightSavingTimes) & " Minutes to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("s", Now(), DayLightSavingTimes) & " seconds to the DayLightSavingTimes!")
我得到了预期的结果:

Running Against Remote Computer Named: MyComputer
14:28:22
It is 0 Months to the DayLightSavingTimes!
It is 3 days to the DayLightSavingTimes!
It is 58 hours to the DayLightSavingTimes!
It is 3452 Minutes to the DayLightSavingTimes!
It is 207098 seconds to the DayLightSavingTimes!
我需要在远程机器上运行此命令,并将其存储在computerlist.txt上,以获得相同的结果 远程运行它时出现的错误是Microsoft VBScript运行时错误:对象不是集合。

有什么提示吗


谢谢

您的问题是如何在computerlist.txt中为每台计算机执行代码?在我看来,这似乎是您所要求的,因为您的初始代码块显示文件名,然后尝试循环给定的字符串。对我有效。您是得到所有远程系统的错误信息,还是只得到特定系统的错误信息?您是否已检查WMI是否正常工作(使用或)?