WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: krasdude on February 21, 2020, 01:08:32 PM

Title: WMI Question
Post by: krasdude on February 21, 2020, 01:08:32 PM
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
Title: Re: WMI Question
Post by: td on February 21, 2020, 01:27:02 PM
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?
Title: Re: WMI Question
Post by: td on February 21, 2020, 01:47:41 PM
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.
Title: Re: WMI Question
Post by: krasdude on February 21, 2020, 03:04:58 PM
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
Title: Re: WMI Question
Post by: td on February 22, 2020, 10:06:21 AM
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)
Title: Re: WMI Question
Post by: td on February 22, 2020, 01:05:03 PM
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.
Title: Re: WMI Question
Post by: krasdude on February 24, 2020, 04:57:30 AM
TD

Thanks, I learned something today.

Much Appreciated