Re: destroying objects within a class

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Tim Newman (Tim.Newman_at_kmcnetwork.org)
Date: 10/19/04


Date: Mon, 18 Oct 2004 20:18:50 -0400

I can accept that and already know that it's true. But the Open function
fails on the next computername that I pass it with error "Object required"
when i try to use the regprovider's methods like reading keys and entries.
So I thought that perhaps it was because it wasn't releasing it's connection
to the previous computername. So perhaps I was ask ing the wrong question.
Can you see anything int he code I provided that would cause the Open
function to not open the next comutername. By the way both computers are
alive and connect fine if it's the first computername passed after launching
the script.
 
Thanks again
>>> Michael Harris (MVP)<mikhar at mvps dot org> 10/18/2004 7:08:46 PM >>>
> problem is, any connection after the first one fails because the
> member function "Close" does not actually destroy the private
> WMIRegProvider object for some reason. And the member function IsOpen
> always returns True after the first connection succeeds.
>
> Why?

MsgBox IsObject(Nothing) 'Always true!

Just take it on faith that assigning Nothing to the private variable
WMIRegProvider does in fact release the reference to the StdRegProv
instance. But then, assigning a new reference via another GetObject does
the same. There is no real need to set the last used instance to nothing
before assigning a new instance. And the last used instance reference will
be released when your script ends and everything goes out of scope.

-- 
Michael Harris
Microsoft.MVP.Scripting
Sammamish WA US