Author Topic: (wmi) vlax-get-object challenge ...  (Read 4939 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(wmi) vlax-get-object challenge ...
« on: December 19, 2007, 04:31:29 PM »
Could have swarn that I used to be able to do this --

Code: [Select]
(setq winmgmts
    (vlax-get-object
        (strcat
            "winmgmts:"
            "{impersonationLevel=impersonate}"
            "!\\\\.\\root\\cimv2"
        )               
    )
)

... once upon a time, but shazbot, no workey, despite many different incarnations including vlax-get-or-create-object, vlax-create-object, vla-getinterfaceobject (via acad app) yada.

If you're curious I'm translating this little snip to lisp.

Any lispin' folks out there have similar functioning code?

Just looking for the snip to secure an instance of winmgmts, once I've that the rest is a cakewalk.

I'll trade ya for this snip ...

Code: [Select]
(defun _AddPrinter ( printerName / objNetwork result )

    ;;==================================================================
    ;;
    ;;  Written 2007/10/xx Michael Puckett
    ;;
    ;;------------------------------------------------------------------
    ;;
    ;;  Argument printerName must be a unc path to a valid device, e.g.
    ;;
    ;;      (_AddPrinter "\\\\server_name\\printer_name")
    ;;
    ;;==================================================================
   
    ;;  translated from vbscript code (http://tinyurl.com/2tcldx) ...
    ;;
    ;;      Set objNetwork = CreateObject("Wscript.Network")
    ;;      objNetwork.AddWindowsPrinterConnection "\\atl-ps-01\Xerox300"

    (setq result
        (null
            (vl-catch-all-error-p
                (vl-catch-all-apply
                   '(lambda ( )
                        (vlax-invoke
                            (setq objNetwork
                                (vlax-create-object "Wscript.Network")
                            )
                           'AddWindowsPrinterConnection
                            printerName
                        )
                    )
                )           
            )
        )               
    )

    ;;  cleanup isle 4
   
    (vlax-release-object objNetwork)
   
    ;;  let caller know if we were successful ...
   
    result
   
)

Thanks!

:)
« Last Edit: December 19, 2007, 04:34:44 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8735
  • AKA Daniel
Re: (wmi) vlax-get-object challenge ...
« Reply #1 on: December 20, 2007, 12:18:49 AM »
would something like this work?

Code: [Select]
(defun c:doit ( / item meth1 meth2 s wmi x)
 (vl-load-com)
 (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
       meth1 (VLAX-INVOKE WMI 'ConnectServer "." "\\root\\cimv2" nil nil nil nil nil nil)
       meth2 (vlax-invoke meth1 'ExecQuery "SELECT * FROM Win32_Printer")
       s (vlax-for item meth2 (setq x (cons(cons (vlax-get item 'Name)(vlax-get item 'Location))x)))
 )
 (vlax-release-object wmi)
 s
)


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8735
  • AKA Daniel
Re: (wmi) vlax-get-object challenge ...
« Reply #2 on: December 20, 2007, 01:03:44 AM »
Also, I think in this case .. impersonationLevel=impersonate by default
I just don't know how to change it  :laugh:

Code: [Select]
(defun c:TestImpersonationLevel ( / meth1 s security wmi)
 (vl-load-com)
 (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
       meth1 (VLAX-INVOKE WMI 'ConnectServer "." "\\root\\cimv2" nil nil nil nil nil nil)
       Security (vlax-get meth1 'Security_)
 )
 (vlax-dump-object Security t)
 (vlax-release-object wmi)
 s
)

edit:  here are some others ...
« Last Edit: December 20, 2007, 06:25:55 AM by Daniel »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (wmi) vlax-get-object challenge ...
« Reply #3 on: December 20, 2007, 07:17:48 AM »
Excellent | Perfect Daniel -- that gives me the nudge I needed.

I was so close, yet so far. I gave up after trying a bunch of variants are pretty close to the (vlax-create-object "WbemScripting.SWbemLocator") call, like (vlax-create-object "WbemScripting.SWbemServices") but they returned nil so I thought "that doesn't work". Should have written a little interrogator to just walk thru every class (SWbemDateTime thru SWbemSink) to determine which ones could be instantiated via (vlax-create-object "WbemScripting.ClassName"). Eventually SWbemLocator would have worked.

But -- that's the "I don't know better, so I'll use my sledgehammer interrogation methods" way. How did you determine SWbemLocator would be the entry point?

I'll be trying your stuff out later this morning. Thanks for taking the time to figure it out and for sharing -- it is greatly appreciated Daniel.

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (wmi) vlax-get-object challenge ...
« Reply #4 on: December 20, 2007, 07:40:53 AM »
... How did you determine SWbemLocator would be the entry point?

This is a good starting point.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8735
  • AKA Daniel
Re: (wmi) vlax-get-object challenge ...
« Reply #5 on: December 20, 2007, 08:19:12 AM »
... How did you determine SWbemLocator would be the entry point?

This is a good starting point.

:)

Ha, you got it!
Here  http://msdn2.microsoft.com/en-us/library/aa389744.aspx
here http://msdn2.microsoft.com/en-us/library/aa389763(VS.85).aspx 
and from the big daddy master programmer http://www.caddzone.com/wmi.lsp

Every lisper should have a copy of the WSH and WMI help files close by  :angel:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (wmi) vlax-get-object challenge ...
« Reply #6 on: December 20, 2007, 09:28:22 AM »
Every lisper should have a copy of the WSH and WMI help files close by.

Enthusiastically agree <quote> vbscript won't cost you anything, runs on all the windows computers you may encounter up to and including vista and while not the most elegant language, does allow you to automate a wide spectrum of mundane tasks </quote>.

VBScript Programmer's Reference (Worx) ain't half bad either, despite the fact I'm not usually a Wrox fan. I didn't have access to it yesterday as it was at home (just started with a new employer Monday so I have to lug my books in a couple at a time). Today it's at the ready.

I respect Tony's expertise and work a lot but I won't be looking at his (caddzone) stuff. To answer the "why" in advance (1) what I develop may end up in commercial applications down the road (2) I don't want solutions -- I just want the map.

:)

(Thank you nonetheless for the links).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (wmi) vlax-get-object challenge ...
« Reply #7 on: December 20, 2007, 09:42:27 AM »
Another tip (for the 1% crowd) -- if you reference the Microsoft WMI Scripting V1.2 Library in VB / VBA (typically located at C:\WINDOWS\System32\wbem\wbemdisp.tlb) you can use the Object Browser (F2) to casually browse all the classes and their properties / methods / constants. If you're abusing tlbinf32.dll you can do same / similar from lisp.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8735
  • AKA Daniel
Re: (wmi) vlax-get-object challenge ...
« Reply #8 on: December 20, 2007, 09:59:33 AM »
Excellent idea  8-), Visual studio will work too!

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8735
  • AKA Daniel
Re: (wmi) vlax-get-object challenge ...
« Reply #9 on: December 20, 2007, 10:07:11 AM »
Wasn’t your hump on the other side? :lol:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (wmi) vlax-get-object challenge ...
« Reply #10 on: December 20, 2007, 10:09:25 AM »
Indeed. Not as sexy but (word wrap will make it ugly but the info is there) ...

(setq
    locater  (vlax-create-object "WbemScripting.SWbemLocator")
    service  (vlax-invoke locater 'ConnectServer)
)



(_Dump locater)

(PROPERTY VALUE ACCESS VISIBILITY)

("Security_" #<VLA-OBJECT ISWbemSecurity 0dbe2d10> READONLY NORMAL)

(METHOD ARGUMENTS ACCESS)

("AddRef" nil RESTRICTED)
("ConnectServer" (("strServer" STR OPTIONAL) ("strNamespace" STR OPTIONAL) ("strUser" STR OPTIONAL) ("strPassword" STR OPTIONAL) ("strLocale" STR OPTIONAL) ("strAuthority" STR OPTIONAL) ("iSecurityFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("GetIDsOfNames" (("riid" EMPTY) ("rgszNames" I1) ("cNames" UINT) ("lcid" UI4) ("rgdispid" I4)) RESTRICTED)
("GetTypeInfo" (("itinfo" UINT) ("lcid" UI4) ("pptinfo" VOID)) RESTRICTED)
("GetTypeInfoCount" (("pctinfo" UINT)) RESTRICTED)
("Invoke" (("dispidMember" I4) ("riid" EMPTY) ("lcid" UI4) ("wFlags" UI2) ("pdispparams" EMPTY) ("pvarResult" variant) ("pexcepinfo" EMPTY) ("puArgErr" UINT)) RESTRICTED)
("QueryInterface" (("riid" EMPTY) ("ppvObj" VOID)) RESTRICTED)
("Release" nil RESTRICTED)



(_Dump service)

(PROPERTY VALUE ACCESS VISIBILITY)

("Security_" #<VLA-OBJECT ISWbemSecurity 0dc0fdf8> READONLY NORMAL)

(METHOD ARGUMENTS ACCESS)

("AddRef" nil RESTRICTED)
("AssociatorsOf" (("strObjectPath" STR) ("strAssocClass" STR OPTIONAL) ("strResultClass" STR OPTIONAL) ("strResultRole" STR OPTIONAL) ("strRole" STR OPTIONAL) ("bClassesOnly" BOOL OPTIONAL) ("bSchemaOnly" BOOL OPTIONAL) ("strRequiredAssocQualifier" STR OPTIONAL) ("strRequiredQualifier" STR OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("AssociatorsOfAsync" (("objWbemSink" DISPATCH) ("strObjectPath" STR) ("strAssocClass" STR OPTIONAL) ("strResultClass" STR OPTIONAL) ("strResultRole" STR OPTIONAL) ("strRole" STR OPTIONAL) ("bClassesOnly" BOOL OPTIONAL) ("bSchemaOnly" BOOL OPTIONAL) ("strRequiredAssocQualifier" STR OPTIONAL) ("strRequiredQualifier" STR OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)
("Delete" (("strObjectPath" STR) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("DeleteAsync" (("objWbemSink" DISPATCH) ("strObjectPath" STR) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)
("ExecMethod" (("strObjectPath" STR) ("strMethodName" STR) ("objWbemInParameters" DISPATCH OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("ExecMethodAsync" (("objWbemSink" DISPATCH) ("strObjectPath" STR) ("strMethodName" STR) ("objWbemInParameters" DISPATCH OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)
("ExecNotificationQuery" (("strQuery" STR) ("strQueryLanguage" STR OPTIONAL)
("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("ExecNotificationQueryAsync" (("objWbemSink" DISPATCH) ("strQuery" STR) ("strQueryLanguage" STR OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)
("ExecQuery" (("strQuery" STR) ("strQueryLanguage" STR OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)("ExecQueryAsync" (("objWbemSink" DISPATCH) ("strQuery" STR) ("strQueryLanguage" STR OPTIONAL) ("lFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)
("Get" (("strObjectPath" STR OPTIONAL) ("iFlags" I4 OPTIONAL)
("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("GetAsync" (("objWbemSink" DISPATCH) ("strObjectPath" STR OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)
("GetIDsOfNames" (("riid" EMPTY) ("rgszNames" I1) ("cNames" UINT) ("lcid" UI4) ("rgdispid" I4)) RESTRICTED)
("GetTypeInfo" (("itinfo" UINT) ("lcid" UI4) ("pptinfo" VOID)) RESTRICTED)
("GetTypeInfoCount" (("pctinfo" UINT)) RESTRICTED)
("InstancesOf" (("strClass" STR) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("InstancesOfAsync" (("objWbemSink" DISPATCH) ("strClass" STR) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)
("Invoke" (("dispidMember" I4) ("riid" EMPTY) ("lcid" UI4) ("wFlags" UI2) ("pdispparams" EMPTY) ("pvarResult" variant) ("pexcepinfo" EMPTY) ("puArgErr" UINT)) RESTRICTED)
("Put" (("objWbemObject" EMPTY) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("PutAsync" (("objWbemSink" EMPTY) ("objWbemObject" EMPTY) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)
("QueryInterface" (("riid" EMPTY) ("ppvObj" VOID)) RESTRICTED)
("ReferencesTo" (("strObjectPath" STR) ("strResultClass" STR OPTIONAL) ("strRole" STR OPTIONAL) ("bClassesOnly" BOOL OPTIONAL) ("bSchemaOnly" BOOL OPTIONAL) ("strRequiredQualifier" STR OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("ReferencesToAsync" (("objWbemSink" DISPATCH) ("strObjectPath" STR) ("strResultClass" STR OPTIONAL) ("strRole" STR OPTIONAL) ("bClassesOnly" BOOL OPTIONAL) ("bSchemaOnly" BOOL OPTIONAL) ("strRequiredQualifier" STR OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)
("Release" nil RESTRICTED)
("SubclassesOf" (("strSuperclass" STR OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL)) NORMAL)
("SubclassesOfAsync" (("objWbemSink" DISPATCH) ("strSuperclass" STR OPTIONAL) ("iFlags" I4 OPTIONAL) ("objWbemNamedValueSet" DISPATCH OPTIONAL) ("objWbemAsyncContext" DISPATCH OPTIONAL)) NORMAL)

etc.

:)
« Last Edit: December 20, 2007, 08:50:31 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (wmi) vlax-get-object challenge ...
« Reply #11 on: December 20, 2007, 10:10:42 AM »
Wasn’t your hump on the other side? :lol:

Only when posting as Abby.

:lol:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst