Avatar of mmitchell57
mmitchell57 asked on

WMI + VBScript + Windows 2000 = Not working well....

The below code shows what I am working with.  The WMI pulls work great on W2k3 and I get out put and quality data.  They dont' work on W2k.  I don't know why?  From what I've read on the web, it should work fine. Am I missing something?
'------ Constants ------>
Const ForReading = 1
Const ForAppending = 8
Const ForWriting = 2
 
'------ Variables ------>
Dim strComputer
Dim objFileSrc  'source file location
Dim objFSOSrc   'source file object
Dim strFileSrc  'source file location
Dim objFile1    'output file object
Dim strFile1    'output file location
Dim objFSO      'output file location
Dim arr1        'Server Arry from File
Dim minArr()	'Minutes array
Dim secArr()	'Seconds Array
Dim strDiff		'Location for time seperation
 
'----- Initializations ------
On Error Resume Next
 
strFileSrc = "all.ini" 'File to pull server list from
set objFSOSrc = createobject("Scripting.filesystemobject")
set objFileSrc = objFSOSrc.OpenTextFile(strFileSrc, forReading, false)
arr1 = Split(objFileSrc.ReadAll, VbCrLf) 'Load server name array
cnt = ubound(arr1) 'count total number or fields in array
 
For i = 0 to cnt  'loops to populate arrays with minute and second data
	strComputer = arr1(i) 'load Server Name variable.
	'msgbox arr1(i)
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime")
	For Each objItem in colItems
		redim Preserve minArr(i) 'prep array location
		minArr(i) = objItem.Minute 'load array location
		redim Preserve secArr(i) ' prep array location
		secArr(i) =  objItem.Second 'load array location
	Next
Next
 
for i = 1 to cnt  'time difference and reporting
	strDiff = minArr(0) - minArr(i) 'find difference
	'msgbox strDiff & " Is the difference"
	if strDiff <> zero then "if there's a time difference
		strFile1 = arr1(i) & "_Err.txt" 'file name creation
		set objFSO = CreateObject("Scripting.FileSystemObject")
		set objFile1 = objFSO.CreateTextFile(strFile1, ForWriting, true)
		objFile1.writeline "Minutes on " & arr1(0) & " is " & minArr(0) & "." & VbCrLf & _
							"Minutes on " & arr1(i) & " is " & minArr(i) & "." & VbCrLf & _
							"Total difference is " & strDiff & "." 'writing file
		objFile1.Close	'Closing file
	else
		strFile1 = arr1(i) & "_Good.txt" 'file name creation
		set objFSO = CreateObject("Scripting.FileSystemObject")
		set objFile1 = objFSO.CreateTextFile(strFile1, ForWriting, true)
		objFile1.writeline "Minutes on " & arr1(0) & " is " & minArr(0) & "." & VbCrLf & _
							"Minutes on " & arr1(i) & " is " & minArr(i) & "." & VbCrLf & _
							"Total difference is " & strDiff & "." 'writing file
		objFile1.Close	'closing file. 
	end if
Next
 
msgbox "DONE!"

Open in new window

VB Script

Avatar of undefined
Last Comment
mmitchell57

8/22/2022 - Mon
Krys_K

Hi There

Hate to be the bearer of bad news but this class (Win32_LocalTime) is not suppported in Win2000
See here
http://msdn.microsoft.com/en-us/library/aa394171(VS.85).aspx

Regards
Krystian
ASKER CERTIFIED SOLUTION
Krys_K

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
mmitchell57

Thank you again for your help. :)  I'm thinking i'll have to build the script based on if it's w2k3 or w2k.  I appreciate it.
Krys_K

your welcome. thanks for the grade and points.

Not sure how comfortable you are with scripting but you could make it work as one script by doing a check for which OS is on the machine then run the correct bit of time code.

Regards
Krystian
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
mmitchell57

That's what I was thinking about doing. Do a WMI on what OS it was then depending, activate which script I want based on the OS.  It looks like the UTC is a mess but with some parsing it'll give me what I need to know. :)  Thank you again. :)