WMI Question

Started by krasdude, February 21, 2020, 01:08:32 PM

Previous topic - Next topic

krasdude

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

td

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?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

krasdude

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

td

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
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Here is your line with the simple change:

Code (winbatch) Select
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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

krasdude

TD

Thanks, I learned something today.

Much Appreciated