1

I'm working on a small proj in Blueprism, on mspaint.exe to draw few schematics. As BP allows us to switch between similar attached apps, I want to switch from first window to second window of mspaint. But as both are not saved with any file-name, the windows text is "Untitled - Paint" for both.

In Blueprism, when there are more than 1 instances open for an exe, all with same window title, cannot attach to any open instance.

Tried attaching with exact or wildcard match as well as child-index selection (any one of them + process name in nav. stage), all open instances respond true. I think that, there is no instance number given by the exe (mspaint) to OS, so that BP can identify it.

In Navigation stage, giving the child-index, is giving exception :
"More than one application matched the criteria".

If title is same and child-index is unobtainable, what is the usual way to attach a window? Is there any method to get the unique window-handle and use it?

Siva
  • 21
  • 1
  • 5
  • Can you assign different handles to each instance? – Badda_Bing Oct 16 '19 at 13:34
  • Window handle itself is not available through BP. We can get PID of any particular running process (all instances of it) in a collection through Memory stats which is the closest and best method I can think of. But we cannot make use of it when attaching, as window-text is the only thing we can use there. – Siva Oct 17 '19 at 20:15
  • You could write a code stage to extract the individual window handle for each instance of your application and use a further one to activate the window by handle as required. Or, save the file in Paint with a name when you open each instance, and delete the files when you are done - this would make the window titles different enough for you to be able to switch between them... – Dave Oct 21 '19 at 10:21
  • @Dave, OK will try to work on the code stage - will be great if I can get it like that, so need to do some R&D in C#. Yes saving and getting the title is what I'm doing right now. Also, as PID is already available in BP, will it be possible to custom code to attach using PID itself, would be much more easy, right? – Siva Oct 24 '19 at 16:00

1 Answers1

0

you can attach to a target application via PID in your attach stage. Doing it this way is very very tricky and will make for a cumbersome process so though yes you can do it, I'd really re-visit your design and make sure you're doing the right design choices.

enter image description here

The image here is a quick schematic I drew up which does what you're looking for. you can launch the application with utility environment launch process and proivde it the path to the target application usually

C:\Windows\System32\mspaint.exe

once launched you can then identify the PID of each instance and attach to them. When you attach make sure you control your detach/attach decisions as an object can only attach to one instance at a time so either have a seperate object to circumvent this or have your actions have very structured well-defined criteria to manage attach and detaching constantly in your process as you switch between two applications.

the XML code to do the image is here, please read the notes. There is also a sample attach stage (with a purposeful error in it). You should be able to step through the other code easily enough. Just copy paste it into your diagram area.

<process name="__selection___test" type="object" runmode="Exclusive">
<stage stageid="62af981b-d1b4-425d-9beb-5dd9663ded2b" name="Attach" type="Navigate">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        -270
    </displayx>
    <displayy>
        210
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <step>
        <element id="859d3912-cecd-4456-9be2-9bd6a73f8717" />
        <action>
            <id>
                AttachApplication
            </id>
            <arguments>
                <argument>
                    <id>
                        WindowTitlesCollection
                    </id>
                    <value>
                    </value>
                </argument>
                <argument>
                    <id>
                        WindowTitle
                    </id>
                    <value>
                    </value>
                </argument>
                <argument>
                    <id>
                        ProcessName
                    </id>
                    <value>
                    </value>
                </argument>
                <argument>
                    <id>
                        ProcessID
                    </id>
                    <value>
                        put your process id here
                    </value>
                </argument>
                <argument>
                    <id>
                        Username
                    </id>
                    <value>
                    </value>
                </argument>
                <argument>
                    <id>
                        ChildIndex
                    </id>
                    <value>
                    </value>
                </argument>
            </arguments>
        </action>
    </step>
</stage>
<stage stageid="3b3fbe62-76da-4757-846e-30deaee86f35" name="get process information" type="Action">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        15
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <inputs>
        <input type="collection" name="Process Names" narrative="The names of the processes to get memory statistics for" expr="[Processes]" />
    </inputs>
    <outputs>
        <output type="collection" name="Process Statistics" narrative="A collection of process statistics including the working set and the virtual memory size" stage="Process Statistics" />
    </outputs>
    <onsuccess>
        ba3fa046-a5c9-4bd2-b15d-26946e25c160
    </onsuccess>
    <resource object="Utility - DXW - Environment" action="Read Memory Stats" />
</stage>
<stage stageid="ef10a40e-34d6-4645-9e3e-c2abfa823b38" name="Working Set" type="Data">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        135
    </displayx>
    <displayy>
        15
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        number
    </datatype>
    <initialvalue />
    <private />
    <alwaysinit />
</stage>
<stage stageid="731b76e6-98a8-4e7f-879e-e576aecd82d8" name="Process Statistics" type="Collection">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        135
    </displayx>
    <displayy>
        105
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        collection
    </datatype>
    <private />
    <alwaysinit />
    <collectioninfo>
        <field name="Process Name" type="text" />
        <field name="PID" type="number" />
        <field name="Working Set" type="number" />
        <field name="Virtual Memory" type="number" />
    </collectioninfo>
</stage>
<stage stageid="6ffde746-c61b-45cc-83fe-b86f86cdd8af" name="Processes" type="Collection">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        135
    </displayx>
    <displayy>
        60
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        collection
    </datatype>
    <private />
    <alwaysinit />
    <collectioninfo>
        <field name="Processes" type="text" />
    </collectioninfo>
    <initialvalue>
        <row>
            <field name="Processes" type="text" value="mspaint" />
        </row>
    </initialvalue>
</stage>
<stage stageid="ba3fa046-a5c9-4bd2-b15d-26946e25c160" name="Note3" type="Note">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        now we have the first PID
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        75
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        2c96c44a-38c9-449d-93a2-e06e5280560f
    </onsuccess>
</stage>
<stage stageid="2c96c44a-38c9-449d-93a2-e06e5280560f" name="record PSID" type="Calculation">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        120
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        aacc1662-0c73-4dc6-a49c-aae3d2bc2485
    </onsuccess>
    <calculation expression="[Process Statistics.PID]" stage="First mspaint PID" />
</stage>
<stage stageid="586fd363-1640-4ef7-ab19-1352cc9b8861" name="First mspaint PID" type="Data">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        135
    </displayx>
    <displayy>
        165
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        text
    </datatype>
    <initialvalue />
    <private />
    <alwaysinit />
</stage>
<stage stageid="a7f6bfb6-5cd3-4f10-8e23-82e271515278" name="get process information" type="Action">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        240
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <inputs>
        <input type="collection" name="Process Names" narrative="The names of the processes to get memory statistics for" expr="[Processes]" />
    </inputs>
    <outputs>
        <output type="collection" name="Process Statistics" narrative="A collection of process statistics including the working set and the virtual memory size" stage="Process Statistics" />
    </outputs>
    <onsuccess>
        5b9affa9-98db-4014-98b7-4a7b559b5cd1
    </onsuccess>
    <resource object="Utility - DXW - Environment" action="Read Memory Stats" />
</stage>
<stage stageid="5b9affa9-98db-4014-98b7-4a7b559b5cd1" name="Note3" type="Note">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        now we have the second PID so we loop to find it
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        300
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        b6c496da-d5b7-4ebb-9a99-98c5fc3f29c2
    </onsuccess>
</stage>
<stage stageid="1109b7bc-dbbe-4c1c-9af1-5da02bf2a229" name="record PSID" type="Calculation">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        480
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        2ca14198-33a5-43db-b9ad-6970797c2b36
    </onsuccess>
    <calculation expression="[Process Statistics.PID]" stage="First mspaint PID" />
</stage>
<stage stageid="aacc1662-0c73-4dc6-a49c-aae3d2bc2485" name="Launch Application" type="Action">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        180
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <inputs>
        <input type="text" name="Application" narrative="The application or short cut to start" expr="&quot;C:\Windows\System32\mspaint.exe&quot;" />
        <input type="text" name="Arguments" narrative="Any arguments needed for the app" expr="" />
    </inputs>
    <onsuccess>
        a7f6bfb6-5cd3-4f10-8e23-82e271515278
    </onsuccess>
    <resource object="Utility - DXW - Environment" action="Start Process" />
</stage>
<stage stageid="b6c496da-d5b7-4ebb-9a99-98c5fc3f29c2" name="loop PIDs found" type="LoopStart">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        360
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        f00d91ee-116d-44e1-8d42-a7cb23c9983e
    </onsuccess>
    <groupid>
        f4c4a30f-44b1-4c6a-a632-a1b46719e8d1
    </groupid>
    <looptype>
        ForEach
    </looptype>
    <loopdata>
        Process Statistics
    </loopdata>
</stage>
<stage stageid="2ca14198-33a5-43db-b9ad-6970797c2b36" name="loop PIDs found" type="LoopEnd">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
        
        
        
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        540
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        cb91afa2-8a34-4fda-82a6-d95335ce534e
    </onsuccess>
    <groupid>
        f4c4a30f-44b1-4c6a-a632-a1b46719e8d1
    </groupid>
</stage>
<stage stageid="ec0a4f36-ac09-4959-82c9-1bedadb63258" name="Second msPaint PID" type="Data">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        180
    </displayx>
    <displayy>
        480
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        text
    </datatype>
    <initialvalue />
    <private />
    <alwaysinit />
</stage>
<stage stageid="cb91afa2-8a34-4fda-82a6-d95335ce534e" name="Note4" type="Note">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        now perform your attach functions. remember an object can only attach to one thing at a time so either make a new object to have one for each instance or make one object and have strict control over your attach and detach functions
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        600
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
</stage>
<stage stageid="f00d91ee-116d-44e1-8d42-a7cb23c9983e" name="Is it the same PID?" type="Decision">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        420
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <decision expression="[Process Statistics.PID]=[First mspaint PID]" />
    <ontrue>
        cafab8cb-4d5e-48d9-872f-07f3a6b4cd65
    </ontrue>
    <onfalse>
        1109b7bc-dbbe-4c1c-9af1-5da02bf2a229
    </onfalse>
</stage>
<stage stageid="cafab8cb-4d5e-48d9-872f-07f3a6b4cd65" name="Anchor1" type="Anchor">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
    </narrative>
    <displayx>
        90
    </displayx>
    <displayy>
        420
    </displayy>
    <displaywidth>
        10
    </displaywidth>
    <displayheight>
        10
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        9eabbb67-c740-4376-b9e9-4ec0db2ef909
    </onsuccess>
</stage>
<stage stageid="9eabbb67-c740-4376-b9e9-4ec0db2ef909" name="Anchor2" type="Anchor">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
    </narrative>
    <displayx>
        90
    </displayx>
    <displayy>
        540
    </displayy>
    <displaywidth>
        10
    </displaywidth>
    <displayheight>
        10
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        2ca14198-33a5-43db-b9ad-6970797c2b36
    </onsuccess>
</stage>
<stage stageid="ee281457-bd05-497a-b11d-01aff60efc6b" name="Launch Application" type="Action">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        -45
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <inputs>
        <input type="text" name="Application" narrative="The application or short cut to start" expr="&quot;C:\Windows\System32\mspaint.exe&quot;" />
        <input type="text" name="Arguments" narrative="Any arguments needed for the app" expr="" />
    </inputs>
    <onsuccess>
        3b3fbe62-76da-4757-846e-30deaee86f35
    </onsuccess>
    <resource object="Utility - DXW - Environment" action="Start Process" />
</stage>
</process>
Dexter Whelan
  • 414
  • 3
  • 15
  • Dexter, sorry didn't have a BP PC to work out for some time due to lock down (and hence late to comment). Then I tried to import your XML file which is giving the attachment error (u said u purposeffully put it). Looking at the schematic I've no idea what u exactly meant. As told first hand, yes getting PID is possible but attaching will never work by giving PID to BP. Is it some other way u did? Why was the error made - w/o importing, how can I even analyze? – Siva Jul 18 '20 at 15:42
  • 1
    The last line of XML file : is also missing. – Siva Jul 18 '20 at 15:44
  • If u meant to attach to a first instance and check for stored PID and if not the one needed, detach and attach another will not work as first attach stage itself will error out. Or maybe something I'm missing here. Thanks for trying to help in so much detail. – Siva Jul 18 '20 at 15:55
  • Hi @Siva What do you mean by 'attaching will never work by giving PID to BP'? It will work, I have done it in this code sample. Not sure why you think it won't work? This example is only to showcase that it CAN be done, when you actually implement attaching functionality you will need to use read stage and IsConnected to verify connection before attaching a second time to avoid that error. Just verified you can attach an object to an application via PID right there, suggest you read the navigate stage for attaching once more or test it more. Also thank you for missing tag. fixed now – Dexter Whelan Jul 24 '20 at 09:54
  • Also, you do not need to attach to get PID FYI. You get PID from using environment function to get the process names that are running, then you get the PID from that output to use that as an attach function. So in this instance there is no first/second attach only one attach when you attach with PID> if you want to run a second attach you need to detach first then attach to second instance – Dexter Whelan Jul 24 '20 at 09:56
  • 1
    What do you mean by 'attaching will never work by giving PID to BP'? Ans : What I said was that in BP, there is no option to tell in BP's 'Attach-Stage' to attach to a window with a particular PID. Only options I see are : Win Title (collection), Win Title, Proc name, Child Index. We can test and find which window has what PID, but how do I tell BP, to be particular about that window while attaching? I'm on BP version 5.x. – Siva Aug 01 '20 at 16:38
  • 1
    I got what you are trying to tell. Analyzing your XML file I found that : You are on latest version of BP and in that, there is an additional stage called "AttachApplication" which has 2 extra args : ProcessID, Username. This is why I can't even import your XML file and do an analysis. These are missing in my BP (older version). So case closed (Latest BP release has issue fixed). Thank you. – Siva Aug 01 '20 at 19:56
  • Ah that would be the issue right there! Coincidentally found a link explainign the steps further here https://www.rpamentor.com/learnersblog/1pqm2ol4ndtr1wn9r8ut3fbm5cysaz however if you don't have Blue Prism version 6 or above then you won't have the ability to do what I'm drawing out! Sorry for the confusion there I thought the PID attach was available on other versions but I guess not! Maybe when you upgrade you can roll into the v 6 one, what version are you on currently? V5.x? – Dexter Whelan Aug 07 '20 at 18:08