"Jo" wrote:
> Hello,
>
> Sorry for my very bad English...
>
> I have a problem when I tried to read registry on remotes computers.
> The code must run under VBA Excel. The final purpose is to extract
> from print servers the list of installed printers with ip address.
> Remotes servers are on various domains without trusts relationships
> and various OS like W2003, W2K and NT4.
>
> When I use this code:
>
> Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
> oReg = objSWbemLocator.ConnectServer(strSrvName, "root
> \default:StdRegProv", strDomain & "\" & strUser, strPassword)
You're missing a Set here, SWbemLocator.ConnectServer returns SWbemServices
object (even if you include the class name in the namespace path)
strSrvName = "."
Set objSWbemLocator = CreateObject _
("WbemScripting.SWbemLocator")
Set oReg = objSWbemLocator.ConnectServer _
(strSrvName, "root\default:StdRegProv")
Debug.Print TypeName(oReg)
Set StdRegProv = oReg.Get("StdRegProv")
For Each Method In StdRegProv.Methods_
Debug.Print Method.Name
Next
(I was only able to test this locally)
In the second code snippet you also missed a Set:
strSrvName = "."
Set objSWbemLocator = CreateObject _
("WbemScripting.SWbemLocator")
' Need Set here:
Set objSWbemServices = objSWbemLocator.ConnectServer _
(strSrvName, "root\default")
Set oReg = objSWbemServices.Get("StdRegProv")
For Each Method In oReg.Methods_
Debug.Print Method.Name
Next
--
urkec
|