Author Topic: WMI Question  (Read 250 times)

krasdude

  • Newbie
  • *
  • Posts: 21
WMI Question
« 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

td

  • Tech Support
  • *****
  • Posts: 3490
    • WinBatch
Re: WMI Question
« Reply #1 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?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 3490
    • WinBatch
Re: WMI Question
« Reply #2 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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

krasdude

  • Newbie
  • *
  • Posts: 21
Re: WMI Question
« Reply #3 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

td

  • Tech Support
  • *****
  • Posts: 3490
    • WinBatch
Re: WMI Question
« Reply #4 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
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 3490
    • WinBatch
Re: WMI Question
« Reply #5 on: February 22, 2020, 01:05:03 pm »
Here is your line with the simple change:

Code: Winbatch
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

  • Newbie
  • *
  • Posts: 21
Re: WMI Question
« Reply #6 on: February 24, 2020, 04:57:30 am »
TD

Thanks, I learned something today.

Much Appreciated