We help IT Professionals succeed at work.
Get Started

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

mmitchell57
mmitchell57 asked
on
480 Views
Last Modified: 2012-05-06
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

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE