Help with Function Command
From: Alisdair Philp (ally.philp_at_dial.pipex.com)
Date: 09/20/04
- Next message: Bob Barrows [MVP]: "Re: Fixes to Scripting 5.6?"
- Previous message: Neil Pike: "Re: Fixes to Scripting 5.6?"
- Next in thread: Bob Barrows [MVP]: "Re: Help with Function Command"
- Reply: Bob Barrows [MVP]: "Re: Help with Function Command"
- Reply: Steven Burn: "Re: Help with Function Command"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 20 Sep 2004 20:07:45 +0100
I'm trying to write a script that connects to servers from a text file read
into a dictionary to get uptime from them. Uptime code is taken from
Microsoft site, but when this runs I get a syntax error at the Function
section. MS code works OK on a PC without the Dictionary code to read in a
servers.txt file. Can anyone help on this?
Thanks in Advance
'Read Server List Text File and Create Dictionary of Server Names
Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\servers.txt", ForReading)
i = 0
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
For Each objItem in objDictionary
StrComputer = objDictionary.Item(objItem)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)
Wscript.Echo dtmSystemUptime
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
13, 2))
End Function
next
- Next message: Bob Barrows [MVP]: "Re: Fixes to Scripting 5.6?"
- Previous message: Neil Pike: "Re: Fixes to Scripting 5.6?"
- Next in thread: Bob Barrows [MVP]: "Re: Help with Function Command"
- Reply: Bob Barrows [MVP]: "Re: Help with Function Command"
- Reply: Steven Burn: "Re: Help with Function Command"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|