Author Topic: Can we check if a certain process in windows is running with autolisp?  (Read 3376 times)

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 1105
Question in the title.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #2 on: February 15, 2018, 11:37:39 AM »
Code: [Select]
(defun vk_ReleaseObjects (lst)
  (foreach o (if (atom lst)
       (list lst)
       lst
     )
    (and o
(= (type o) 'VLA-OBJECT)
(not (vlax-object-released-p o))
(vlax-release-object o)
    )
  )
)
(defun vk_GetWbem (Class Props / LocatorObj ServiceObj ObjectSetObj OutList)
  (and (setq LocatorObj (vlax-create-object "WbemScripting.SWbemLocator"))
       (setq ServiceObj (vlax-invoke LocatorObj 'ConnectServer "." "root\\cimv2" nil nil nil nil nil nil))
       (setq ObjectSetObj (vlax-invoke ServiceObj 'ExecQuery (strcat "SELECT * FROM " Class)))
       (vlax-for Obj ObjectSetObj
(setq OutList (cons (mapcar (function (lambda (p) (vlax-get Obj p))) Props) OutList))
       )
  )
  (vk_ReleaseObjects (list ObjectSetObj ServiceObj LocatorObj))
  (reverse OutList)
)
Code: [Select]
(vk_GetWbem "Win32_Process" (list "Name" "ExecutablePath" "CommandLine"))
one can also grab lots of other stuff with that
Code: [Select]
(vk_GetWbem "Win32_NetworkAdapterConfiguration" (list "MACAddress" "IPAddress"))
(vk_GetWbem "Win32_Processor" (list "ProcessorId" "Manufacturer" "CurrentClockSpeed"))

dubb

  • Swamp Rat
  • Posts: 1105
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #3 on: February 15, 2018, 12:21:28 PM »
Awesome! this works pretty good. All I need to do is modify it to verify a specific process. This script returns an entire list of processes, so I use assoc to locate the process i need.

Code: [Select]
(defun vk_ReleaseObjects (lst)
  (foreach o (if (atom lst)
       (list lst)
       lst
     )
    (and o
(= (type o) 'VLA-OBJECT)
(not (vlax-object-released-p o))
(vlax-release-object o)
    )
  )
)
(defun vk_GetWbem (Class Props / LocatorObj ServiceObj ObjectSetObj OutList)
  (and (setq LocatorObj (vlax-create-object "WbemScripting.SWbemLocator"))
       (setq ServiceObj (vlax-invoke LocatorObj 'ConnectServer "." "root\\cimv2" nil nil nil nil nil nil))
       (setq ObjectSetObj (vlax-invoke ServiceObj 'ExecQuery (strcat "SELECT * FROM " Class)))
       (vlax-for Obj ObjectSetObj
(setq OutList (cons (mapcar (function (lambda (p) (vlax-get Obj p))) Props) OutList))
       )
  )
  (vk_ReleaseObjects (list ObjectSetObj ServiceObj LocatorObj))
  (reverse OutList)
)
Code: [Select]
(vk_GetWbem "Win32_Process" (list "Name" "ExecutablePath" "CommandLine"))
one can also grab lots of other stuff with that
Code: [Select]
(vk_GetWbem "Win32_NetworkAdapterConfiguration" (list "MACAddress" "IPAddress"))
(vk_GetWbem "Win32_Processor" (list "ProcessorId" "Manufacturer" "CurrentClockSpeed"))

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #4 on: February 15, 2018, 12:44:33 PM »
<code>
one can also grab lots of other stuff with that
<code>

Very nice!
Russian hacker spotted..  :lol:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #5 on: February 15, 2018, 01:01:36 PM »
Russian hacker
hehe :)
neither of those
just a common ukrainian ;)

dubb

  • Swamp Rat
  • Posts: 1105
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #6 on: February 15, 2018, 01:28:46 PM »
I always think of vodka when I see VovKa.  :lmao:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #7 on: February 15, 2018, 03:34:19 PM »
Another take (may be flawed, enduring crushing headache) ...

Code: [Select]
(defun _WbemGet ( class props / locator service query temp result )

    (vl-catch-all-apply 'eval
       '(   (vlax-for x
                (setq query
                    (vlax-invoke
                        (setq service
                            (vlax-invoke
                                (setq locator (vlax-create-object "WbemScripting.SWbemLocator"))
                                'ConnectServer "." "root\\cimv2" nil nil nil nil nil nil
                            )   
                        )
                        'ExecQuery
                        (strcat "SELECT * FROM " class)
                    )
                )                         
                (setq temp
                    (cons
                        (mapcar
                            (function (lambda (p) (vl-catch-all-apply 'vlax-get (list x p))))
                            (if (listp props) props (list props))
                        )
                        temp
                    )
                )       
            )       
        )
    )

    (foreach x (mapcar 'list (list query service locator))
        (vl-catch-all-apply 'vlax-release-object x)
    )
   
    (foreach l temp
        (or
            (null (apply 'or l))
            (member l result)
            (setq result (cons l result))
        )
    )       

    (if (listp props) result (mapcar 'car result))
   
)

(_WbemGet "Win32_Process" '(Name ExecutablePath CommandLine))
(_WbemGet "Win32_Process" '(Name ProcessID))
(_WbemGet "Win32_Process" 'Name)

Edit: Modified so you can see when you request an invalid property:

(_WbemGet "Win32_Process" '(Name Bogosity))

Cheers.
« Last Edit: February 15, 2018, 06:46:28 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: Can we check if a certain process in windows is running with autolisp?
« Reply #8 on: February 15, 2018, 04:48:37 PM »
did someone say vovka?
« Last Edit: February 15, 2018, 06:32:38 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #9 on: February 15, 2018, 05:29:55 PM »
This thread may also be of interest:

http://www.theswamp.org/index.php?topic=38102

did someone say vovka?

Superb  :lol:

JohnK

  • Administrator
  • Seagull
  • Posts: 10638
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #10 on: February 15, 2018, 05:49:43 PM »
Product of Sweden / Product of Ukraine

Thank goodness, as far as I know, the Swedish and Ukrainian relations are not an issue.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #11 on: February 15, 2018, 06:33:04 PM »
I always think of vodka when I see VovKa.  :lmao:
one of my professors at the university (yep he was an American) told me that my name sounds to him like Volvo (yep it is a Swedish car)
the Swedish and Ukrainian relations are not an issue.
300 years ago we even fought together against Russia :)
did someone say vovka?
and now Swedish vodka... all is interconnected in this world... :)

p.s. you would not believe guys, but my wife teaches Swedish at the university

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #12 on: February 16, 2018, 12:48:51 AM »
What's all the Swedish talk about? :whistling:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #13 on: February 16, 2018, 09:43:14 AM »
What's all the Swedish talk about? :whistling:
i've never met one
have no idea what they are up to  ;-)

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Can we check if a certain process in windows is running with autolisp?
« Reply #14 on: February 18, 2018, 12:33:59 AM »
What about Dan Akroyds Vodka I think it was voted best in world, made in Canada, but some one who chases ghosts needs a good shot every now and then.
A man who never made a mistake never made anything