jnollet Posted August 7, 2007 Share Posted August 7, 2007 Using the following code I nicely get a return of memory size from the named server...Set xSvc = GetObject("winmgmts:\\" & "Server")Set xObjSet = _ xSvc.InstancesOf("Win32_LogicalMemoryConfiguration")For Each xObj In xObjSet memGb = xObj.TotalPhysicalMemory / 1048576 Wscript.Echo "Total Physical Memory (gb): " & _ FormatNumber(memGb, 1) NextI am trying to create an array of the server names and process that array (this works fine)My problem is that I occasionally get a failure in the script on the "For Each" statement saying Error:0X80041013 Code:80041013 Source:(null)This occurs on a specific server as I can place the names of several servers in the above code and it worksbut get the error on one specific server.Any suggestions?Thanks in advance,John Link to comment Share on other sites More sharing options...
jnollet Posted August 8, 2007 Author Share Posted August 8, 2007 I've tried many tests but can't come up with something that works.For example,Tested the GetObject - Err.Number <> 0Tested the ObjectSet - IsEmpty(xObjSet) Or Err.Number <> 0 Tested the Instance Count - nInstanceCount = xObj.Count If Err.Number <> 0 ThenTested all with IsNull also.I've run out of ideas - any suggestions? Link to comment Share on other sites More sharing options...
jesh Posted August 8, 2007 Share Posted August 8, 2007 I've really forgotten most of my VBScript, but typically, when running a for each loop and you are getting null reference errors, you'll want to first check to see if the collection is not null, then run the for each loop, then, in each iteration of the loop, check the set value to see if it is null.In pseudo-code: if xObjSet is not nullfor each xObj in xObjSet if xObj is not null // execute your remaining code end ifnextend if Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.