Re: Help with Function Command

From: Steven Burn (pvt_at_noyb.com)
Date: 09/20/04


Date: Mon, 20 Sep 2004 20:33:07 +0100

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!
"Alisdair Philp" <ally.philp@dial.pipex.com> wrote in message
news:414f2a88$0$15886$cc9e4d1f@news.dial.pipex.com...
> 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
>
>


Relevant Pages

  • Help with Function Command
    ... Uptime code is taken from ... 'Read Server List Text File and Create Dictionary of Server Names ... Const ForReading = 1 ... Set colOperatingSystems = objWMIService.ExecQuery _ ...
    (microsoft.public.scripting.vbscript)
  • RE: VBScript to restart a server
    ... strComputer = "CAM125BW0102" ... Set colOperatingSystems = objWMIService.ExecQuery _ ... For Each objOperatingSystem in colOperatingSystems ... you can make a text file and just read from it with all your server names ...
    (microsoft.public.scripting.vbscript)
  • Win32Shutdown failing with error number 21
    ... I am shutting down a number of servers using the following script. ... The machines are running win2k server or win2k3 server. ... The two which fail are running w2k3 but at least one other that is ... Set colOperatingSystems = objWMIService.ExecQuery _ ...
    (microsoft.public.scripting.vbscript)
  • LastBootUptime Object
    ... reboot of the server i get the value Null on the server as a result of ... Set objWMIService = GetObject("winmgmts:" _ ... Set colOperatingSystems = objWMIService.ExecQuery _ ...
    (microsoft.public.scripting.vbscript)