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
Avatar of Krys_K
Krys_K
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Krys_K
Krys_K
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mmitchell57
mmitchell57

ASKER

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.
Avatar of Krys_K
Krys_K
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of mmitchell57
mmitchell57

ASKER

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. :)
VB Script
VB Script

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

39K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo