0

我需要一个从 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 运行时错误:对象不是集合。

有什么提示吗?

谢谢

4

0 回答 0