Tom
Tue May 20 16:30:10 CDT 2008
On May 20, 4:52 pm, "heintz.la...@gmail.com" <heintz.la...@gmail.com>
wrote:
> On May 11, 9:26 pm, Shoeb1208 <Shoeb1...@discussions.microsoft.com>
> wrote:
>
> > Hi Larry , thanks for the advice. From what i analysed the problem is that
> > the script is not taking the credentials again for the server in each loop.
> > Somehow the objWMIService is not getting refreshed after every loop.
>
> > any suggestions?
>
> Just saw the response. Is there a local administrator account on the
> machines that have the same username and password you could pass in
> the script? You can also add the following to the script so you can
> write out the login informaion being passed to the loop.
>
> arrComputers = Array("comp1","comp2","comp3","comp4","comp5")
> For Each strComputer In arrComputers
> WScript.Echo
> WScript.Echo "=========================================="
> WScript.Echo "Computer: " & strComputer
> WScript.Echo "=========================================="
>
> Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
> Set objWMIService = objSWbemLocator.ConnectServer(strServer, _
> "root\cimv2", _
> strUser, _
> strPassword, _
> "MS_409", _
> "ntlmdomain:" + strDomain)
> wscript.echo "Username:" & strDomain & "\" & strUser _
> " Password:" & strPassword
> For Each objItem in colItems
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "Win32_LogicalDisk instance"
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "Size: " & objItem.Size
> Next
> Next
My guess is that there is an ON ERROR Resume Next statement somewhere
before the code segment posted, because there are multiple errors that
are keeping any useful data from being displayed, even though the
loops still keep running.
For example, the ConnectServer statement references a strServer
variable that is also undefined. Rather, a strComputer variable is
being reference in the FOR loop.
In addition, the colItems collection is undefined in the example.
There needs to be a query, something like before the second FOR
statement ...
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_LogicalDisk")
It is also not clear that the rest of the needed variables, like
strUser and
strPassword are actually being created. It is also assumed that the
same credentials are valid on all machines. If that's not the case,
the correct credentials for each machine must be keyed to the machine
being queried (which the code fragment does NOT do).
Finally, I would throw in line to clear the connection at the end of
the loop to insure that a new connection is made with each pass. (To
save a little time the Set objSWbemLocator line can be moved out of
the loop and only one instantiation is needed.
Maybe this (untested) ...
On Error Goto 0 ' Clears effect of 'On Error Resume Next'
arrComputers = Array("comp1","comp2","comp3","comp4","comp5")
wscript.echo "Username:" & strDomain & "\" & strUser _
" Password:" & strPassword
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = objSWbemLocator.ConnectServer(strComputer,
_
"root\cimv2", _
strUser, _
strPassword, _
"MS_409", _
"ntlmdomain:" & strDomain)
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_LogicalDisk")
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_LogicalDisk instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Size: " & objItem.Size
Next
Set objWMIService = Nothing
Next
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/