Help with Function Command

Help with Function Command

Post by Alisdair P » Wed, 22 Sep 2004 04:07:45


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
 
 
 

Help with Function Command

Post by Steven Bur » Wed, 22 Sep 2004 04:33:07

Move the Function code so it's BELOW the "Next" line

e.g.
Dim x
For x = 1 to 10
wscript.echo MyFunction(x)
Next

Function MyFunction(x)
MyFunction = x + 1
End Function

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!




read

 
 
 

Help with Function Command

Post by Bob Barrow » Wed, 22 Sep 2004 04:34:31


Your antivirus software is probably blocking script.
http://www.yqcomputer.com/

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.