Jump to content

How to get the name desktop icon with the current focus?


Doserox
 Share

Recommended Posts

This one seems pretty straight-forward but I can't find an exact answer.

I'm attempting to simply find and launch a desktop shortcut, verify a window, and close t

My current approach is nothing more than:

$FirstIcon = _GetIconWithFocus()

While $ThisIcon <> $FirstIcon  

    Send("{TAB}")  ;Desktop, not IE

    $ThisIcon = _GetIconWithFocus()

    if stringinstr($ThisIcon, $AppToLaunch) > 0 then

        Send("{ENTER}")  ;Launch!

        Exitloop

    EndIf

Wend

I found an old post regarding a _ExplorerGetSelectedItems UDF

At best it accurately tells me how many Icons are on my desktop, but does not return any text. 

If there is another approach I'm all ears.

Bonus Question: Ultimately this will run under Citrix Desktop, any monsters lurking there that I should be aware?

Thanks in advance,

Edited by Doserox
Hit post by accident
Link to comment
Share on other sites

 

Not sure anymore how to do this from AutoIT natively but the Desktop is class #32769 and as it just a listview you should be able to get all items

 

Regarding citrix it depends what you are saying. Will the script run in Citrix environment then there are not many issues normally. Is your script on a local machine then the citrix frame is just one big bitmap and no objects can be recognized without falling back to OCR stuff (assuming you do not want to write your own Citrix client).    

Link to comment
Share on other sites

@Doserox,

if you know what is the app you want to launch, as you refer to it as

$AppToLaunch

then why are you not taking the direct approach, using the Run command? even if you don't know the executable full path, you can either ShellExecute the icon (.lnk file) or read the executable full path from the icon file, since you obviously know the icon name. desktop icons (.lnk files) are located in the user Desktop folder ("%userprofile%\Desktop"), or in the public Desktop folder (commonly "C:\Users\Public\Desktop").

and as for Citrix - your approach is highly unlikely to work. there are plenty of topics about Citrix/RDP/VNC in this forum, hereunder is one such example. kindly bother yourself with a bit of searching and reading, then if something is unclear, do feel free to ask.

 

EDIT: but if you insist treading that path of simulating clicks and keystrokes, and the title of this topic is actually what you ask (meaning, you want to get the name of the icon that currently has focus), then simply send F2Ctrl+C , and Esc. this triggers the "rename" operation with the icon name highlighted, so you can copy it to clipboard, then cancel the operation with Esc. then get the clipboard content with ClipGet.

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

First off: Thank you both for the great suggestions! 

Junkew: The script will run inside the Citrix environment for the exact reasons you noted: Outside the client OCR is (and has almost always been) unreliable, and a Citrix client is probably way over my head. FYI: had this been XenApp instead of XenDesktop I know I could get the icon text directly from outside the client.

ORBS: All good points. The reason I can't use the run command is two-fold: First is the Citrix "Desktop" is proprietary. It's not a standard MS desktop you might find under a VMWare Workstation. The second is this will run against 300 clients, and no one is certain all clients are configured correctly, hence the automation. Some expected apps may not actually exist, and I want to find an icon before I attempt to launch it, and report it missing in my results.

The F2 Ctrl+C Esc solution, which I really like on a standard MS Windows desktop is also one of those Citrix XenDesktop monsters. In this approach Citrix has it's own custom app list that does not allow renaming. That's why I am asking for ideas to capture the text from an object with the focus. I said Icon to keep the ideas wide. But I'll try the copy and see what the clipboard gives me.

On a side note: I actually prefer simulating keystrokes and mouse clicks (at co-ordinates derived from objects, not hard-coded) because method calls have a nasty habit of performing actions a real-world user could not perform. The most common example is a developer who just covers the interface with a 50% opaque screen to pop a "modal" dialog so they don't have to disable all the front end objects. And with simulated keystrokes we actually find a lot of cruft the nubie developers and most manual testers miss. I think our Developers really hate QA for it, but it makes my ROI a cakewalk. LOL

Link to comment
Share on other sites

@Doserox

let me see if i understand you correctly. you wish to perform the following task (for multiple users, automatically):

1) detect if a specific app is installed for a user

2) if it is installed, then launch it

3) do some QA tests on that app

as for step 3, since you are in a position to prefer user mimicry for QA purposes, then i tend to believe that OCR would be your logical choice. as for steps 1 & 2, i'm quite certain - although with a rather outdated knowledge of the XenDesktop environment, and without one to test on - that they can be achieved programatically.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Even easier than that: Step 1 and Step 2 are right on.

Step 3 is an expected window popped - more than likely with the app name in the title - and the title does not contain the word "error".

Nothing deeper than that.

 

I totally understand your position. I was ecstatic that it appeared I could do all this through my initial POC on XenApp.  But you know things are never what the appear to be. In my experience OCR worked only once, under WinRunner back in the day. The font was no less than 16 point on a high resolution monitor for medical purposes. Beyond that I have not had much success. I've been asked once to use it to bypass Captcha, and I made the point clear, if it DID work against Capptcha, that would defeat the purpose of Captcha. Guess where the majority of the bugs were found - just beyond the Captcha. :)

Link to comment
Share on other sites

26 minutes ago, Doserox said:

... Step 1 and Step 2 are right on.

so you can do that then? and the issue is to detect when a window appears in Step 3? if so, then earlier you mentioned that your QA script would run on the server side of the Citrix session, not the client side. then why would AutoIt windows management functions not work? i'm referring to WinExists(), WinList() and the likes.

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Yeah in XenApp it could all be done easily outside Citrix.  But the solution is now two scripts - one outside that reads from a spreadsheet and launches the Citrix XenDesktop, logs In and blindly launches a second script inside Citrix. The internal one reads from the same spread sheet and tabs about looking for app name matches. That one also does all the Window verification as well and I know enough to do that. It's really just pulling the text from the App "icon" which has the current focus that I only need to solve. I'm not bad at mucking about in IE with AutoIT. It's been many years since I had to do much thick client stuff like this, which I know was AutoIT's original purpose. I'll let you know what happens. I do thank you for your kind patience with me.

Link to comment
Share on other sites

So here's a neat solution -  I found the Keystroke pattern that takes me to the App list in Citrix XenDesktop- WINDOW, Enter key

Then I type the app name as there is a search box right there.

Then I Tab three times, select All and Copy. If the app was found we are back at the Search box. I now have the searchtext in the clipboard.

If the clipboard matches the text I typed  - we have an app. Type enter and it launches. If not we had no match no app was found. Report error.

Not quite as clean as I would like but it's working!  

Link to comment
Share on other sites

#AutoIt3Wrapper_UseX64=N

#include <MsgBoxConstants.au3>

$wshShell = ObjCreate("wscript.shell")
$strDesktop = $WshShell.SpecialFolders("Desktop")
consolewrite("Folder " & $strDesktop  & @CRLF)

Example($strDesktop)

Func Example($strFolder)
    ; Assign a Local variable the search handle of all files in the current directory.
    Local $hSearch = FileFindFirstFile($strFolder & "\*.*")

    ; Check if the search was successful, if not display a message and return False.
    If $hSearch = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.")
        Return False
    EndIf

    ; Assign a Local variable the empty string which will contain the files names found.
    Local $sFileName = "", $iResult = 0

    While 1
        $sFileName = FileFindNextFile($hSearch)
        ; If there is no more file matching the search.
        If @error Then ExitLoop

        ; Display the file name.
        $iResult = consolewrite("File: " & $sFileName & @CRLF)
    WEnd

    ; Close the search handle.
    FileClose($hSearch)
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...