This may be simple but ...
my laptop is in Domain A. I have servers in Domain B. I also have a non-interactive account in Domain B which is in local administrators group. I would like to connect via WMI and check things.
This VB connect works just fine ...
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, _
"Root\CIMv2", _
strUser, _
strPassword, _
"MS_409", _
"ntlmdomain:" + strDomain)
but my WinBatch connect does not ...
Service = Locator.ConnectServer(ComputerName,"root/cimv2",user, pwd,"MS_409","ntlmdomain:" : domain)
All variables set properly. Is there something I am missing?
Thanks everyone
You need to provide more information. Are you getting an error? If so what is the error's text and what additional error information exists when you press the "More Error Info" button, assuming it is enabled?
I did a quick test and was able to connect to another computer on the local subnet using the "WbemScripting.SWbemLocator" object's ConnectServer method.
Unsupported variant-type
I assume I need to convert this
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, _
"Root\CIMv2", _
strUser, _
strPassword, _
"MS_409", _
"ntlmdomain:" + strDomain)
into something WinBatch knows, maybe or maybe just wouldn't work
I should have noticed the colon in your original post. The problem is that the colon operator ":" is overloaded in WIL. It is a string concatenation operator and a COM variant type operator when used in the context of a COM Automation method call.
You have three options. You can place a colon after the coma and before the start of your last parameter, you build the last parameter outside of the call and just pass the variable in the last parameter's position, or you can us the StrCat function to build the value for the last parameter in the last parameter's position.
The article below does not specifically address this issue but it does show how parameter types are specified in COM Automation method calls:
https://docs.winbatch.com/mergedProjects/COM/COM_Types.htm (https://docs.winbatch.com/mergedProjects/COM/COM_Types.htm)
Here is your line with the simple change:
Service = Locator.ConnectServer(ComputerName,"root/cimv2",user, pwd,"MS_409", :"ntlmdomain:" : domain)
Note that the "ntlmdomain:" : domain' is changed to :"ntlmdomain:" : domain. The colon in front of the parameter tells WIL to do the default type conversion. It is equivilant to BSTR:"ntlmdomain:" : domain. WIL will not try to parse the second colon as a variant type indicator because it has already found a variant type inicator for the parameter. So the second colon works as you intended and performs concatenation.
TD
Thanks, I learned something today.
Much Appreciated