GetProcessIDs is great, but

Ideas for new features & functions

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 406
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

GetProcessIDs is great, but

Post by Grovkillen » Fri Feb 10, 2017 12:10 pm

GetProcessIDs is great, I love it but it doesn't take parts of the process name (i.e. search with *). If no process is found it should return 0 in "array_count".

I'd like this to work...

Code: Select all

GetProcessIds>iexplore*,arrIEs
If>arrIEs_count>0
Let>k=0
Repeat>k
  Let>k=k+1
  Let>this_id=arrIEs_%k%
Until>k=arrIEs_count
Let>ME=%Script%

Running: MS14.5.4

User avatar
Marcus Tettmar
Site Admin
Posts: 7118
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: GetProcessIDs is great, but

Post by Marcus Tettmar » Fri Feb 10, 2017 2:43 pm

Correct. This function grew out of a request for ProcessExists to return a count. We didn't want to change behaviour of an existing function so we added this. It was never meant to do a wildstring search. None of the other process functions do. But we can consider that for future.

I would use it in conjunction with ProcessExists:

Code: Select all

ProcessExists>chrome.exe,haveChrome
If>haveChrome=True
 GetProcessIDs>chrome.exe,myArr
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Grovkillen
Automation Wizard
Posts: 406
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: GetProcessIDs is great, but

Post by Grovkillen » Sun Feb 12, 2017 7:46 am

Thanks for info! I thought I'd just give my first impression of the new command. I like it though! :D
Let>ME=%Script%

Running: MS14.5.4

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Re: GetProcessIDs is great, but

Post by zabros2020 » Wed Feb 15, 2017 6:03 am

You could use something like this:

Code: Select all

VBSTART
    Dim list
    Dim tmp
    'returns the number of copies of ProcessName that are running
    'will return 0 if ProcessName is not running
    Function GenerateProcessList()
        Set objSWbemServices = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
        Set colSwbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_Process")
        list = ""
        tmp = ""
        For Each objProcess in colSWbemObjectSet
          'Wscript.Echo "Process Name: " & objProcess.Name
          tmp = objProcess.Name
          list = list &","& tmp
          'Wscript.Echo list
        Next
    End Function
    Function GetProcessList()
      GetProcessList = list
    End Function
VBEND

'find iexplore.exe
Let>findProcess=xplo

VBRun>GenerateProcessList
VBEval>GetProcessList,list
Position>%findProcess%,%list%,0,i
If>i>0
  'do what you need to
  MidStr>%list%,{%i%-10},40,process
  MessageModal>Found process %process%
EndIf
Loving MS's Capabilities!!!

User avatar
Grovkillen
Automation Wizard
Posts: 406
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: GetProcessIDs is great, but

Post by Grovkillen » Thu Feb 16, 2017 7:07 am

Cool VBS code (haven't tested it though). Would you be able to get status of the processes as well? I'm interested in seeing if my script (compiled as exe) is stalling by monitoring their status (i.e. running/not responding). I have multiple exe files running (same script exe) and thus also need to have the whole spectra of running processes (which is now included natively in MS).
Let>ME=%Script%

Running: MS14.5.4

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Re: GetProcessIDs is great, but

Post by zabros2020 » Tue Feb 28, 2017 4:13 am

Not the best solution. But this will find it.
Not sure how it will affect any MS scripts running in terms of screens.

Code: Select all

'**NOTE: Change "Running" in Position>Running,%wText%,1,iPos to Not Responding
'to test leave as Running
'Have Notepad open to test this

VBSTART
    Dim list
    Dim tmp
    'returns the number of copies of ProcessName that are running
    'will return 0 if ProcessName is not running
    Function GenerateProcessList()
        Set objSWbemServices = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
        Set colSwbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_Process")
        list = ""
        tmp = ""
        For Each objProcess in colSWbemObjectSet
          'Wscript.Echo "Process Name: " & objProcess.Name
          tmp = objProcess.Name
          list = list &","& tmp
          'Wscript.Echo list
        Next
    End Function
    Function GetProcessList()
      GetProcessList = list
    End Function
VBEND

'find notepad.exe
Let>findProcess=tepad
Let>appName=Notepad
VBRun>GenerateProcessList
VBEval>GetProcessList,list
Position>%findProcess%,%list%,0,i
WaitReady>0
**BREAKPOINT**
If>i>0
  Run>cmd /c taskkill /im taskmgr.exe /f
  Wait>2
  'Run taskmgr
  Let>fileName=C:\Windows\System32\taskmgr.exe
  Run>cmd /c START "" "%fileName%"
  WaitReady>0
  Wait>2

  'do what you need to
  Let>findHandleFor=Windows Task Manager
  GoSub>Get_WinHandle
  Let>WIN_USEHANDLE=1
  SetFocus>%hWndResult%
  Position>%,%hWndResult%,1,i
  If>i=0
    Let>ObjName=SysListView32
    Let>ObjIndex=1
    GoSub>Get_WindowObjectVars
    Position>Running,%wText%,1,iPos
    If>iPos>0
      'Find your app name here from the returned value in wText
        Separate>%wText%,%CRLF%,wTextList
        Let>i=1
        Repeat>i
            Add>i,1
            Position>%appName%,wTextList_%i%,1,iPos
            If>iPos>0
                'found
                'Now do what you need to
                **BREAKPOINT**
                Let>foundThis=wTextList_%i%
                MessageModal>found %foundThis%

                'EXIT LOOP
                Let>i=%wTextList_Count%
            EndIf
        Until>i=%wTextList_Count%
    EndIf
  EndIf
EndIf

SRT>Get_WinHandle
    Let>WIN_USEHANDLE=0
    Let>hWndResult=%
    GetWindowHandle>%findHandleFor%,hWndResult
END>Get_WinHandle

SRT>Get_WindowObjectVars
    '-------------------------------------------
    '|RETURN VALUES FROM SPEICIFIED OBJECT
    'E.G DATAGRID,FIELD,LABEL ETC
    '-------------------------------------------
    'ALWAYS from hWndResult handle. Get_WinHandle will return hWndResult
    'Returns wText with the text in the object
    'X1,Y1,X2,Y2 returns the position of the object on the screen
    'hWnd returns handle of object
    FindObject>%hWndResult%,%ObjName%,,%ObjIndex%,ObjhWnd,X1,Y1,X2,Y2,result
    'set x y and bottom pos of Object
    Let>posX=%X1%+10
    Let>posY=%Y1%+10
    Let>posB=%Y2%
    Let>WIN_USEHANDLE=1
    GetTextInit
    'Capture text for the object using the returned ObjhWnd handle
    GetWindowTextEx>%ObjhWnd%,wText
END>Get_WindowObjectVars
Loving MS's Capabilities!!!

Post Reply