Sign in to follow this  
Followers 0
Rishav

Selecting an entry from Windows context menu

11 posts in this topic

#1 ·  Posted (edited)

Hi guys

Just picked up AutoIt yesterday so don't know much about it. been playing with it, trying to automate some processes but didn't have much success with one action, which i am sure is quite easy.

What i want to do is to select an entry from the windows context menu and click on it without using the keyboard shortcuts for the entries, mouse clicks or the arrow keys. I want to select the context menu entry based on the text label for that entry.

so say, i have selected a folder and opened the right click context menu with the following items

--Open

--Edit

--Close

i want to click on Edit using its text label "Edit". But am out of ideas on how to proceed with it.

The help file really wasn't much help with this. Most of the stuff went over my head. Searching the forum also didn't help much as i guess my keywords weren't good enough.

Can anyone point me to the right direction with this?

thanks and regards.

Edited by Rishav

Share this post


Link to post
Share on other sites



@Rishav

If it is File related then this will get you going.

; Check if a valid file was specified
$objFSO = ObjCreate( "Scripting.FileSystemObject" )

$strFile = "C:\_FileCopy.au3" ;!!

If Not $objFSO.FileExists( $strFile ) Then 
    ConsoleWrite($strFile & " Does not exist" & @CRLF)
EndIf
$strFolder = $objFSO.GetParentFolderName( $strFile )
$objFSO = ""

; Open the Shell Folders object
$objShell  = ObjCreate( "Shell.Application" )

; Create an object for the specified file's parent folder
$objFolder = $objShell.Namespace( $strFolder )

; Create a collection for the folder's contents
$colFiles  = $objFolder.Items

; Loop through the collection to find the file specified
If $colFiles.Count > 0 Then
    For $objFile In $colFiles
        If StringLower( $objFile.Path ) = StringLower($strFile ) Then
            ; Edit the file with its associated Context Menu command
            $objFile.InvokeVerbEx( "Edit Script" )
        EndIf
    Next
EndIf

Regards,

ptrex

Share this post


Link to post
Share on other sites

Thanks for the reply ptrex. perhaps it will be better if i am more specific.

The exact action i want to perform is to click the "TortoiseSVN" and then the "Export" entry from the windows context menu.

Posted Image

Selecting the proper folder and bringing up the right click menu has been somewhat easy with the following code.

ShellExecute("explorer.exe", "/n,/select," & "C:\TEMP\Test")
WinWaitActive("[CLASS:CabinetWClass]")
Send("{APPSKEY}")

but i don't know how to go about selecting a specific context menu element.

currently i am doing

Send("{down}") 15 times

and then

Send("{Enter}")

which i feel to be extremely inelegant.

Share this post


Link to post
Share on other sites

ummm... anyone?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You are going about this the wrong way altogether. The context menus are all stored in the registry, along with the actual instruction itself.

In this case clicking TortoiseSVN -> Export actually just passes the name of the folder to a command line exe.

You need to find the command that is passed and simply write a function that takes a folder path as a parameter, none of this silly trying to automate explorer.exe.

See here to find the command:

http://windowsxp.mvps.org/context_folders.htm

Even better, here are the TortoiseSVN command line options:

http://tortoisesvn.net/docs/release/Tortoi...automation.html

It looks like export just copies the folder to another location, are you sure this is something you can't do with DirCopy? :P

Edited by weaponx

Share this post


Link to post
Share on other sites

I didn't know that at all.

I'll spike a bit with that.

Thanks a lot weaponx and ptrex. you guys were quite helpful.

Share this post


Link to post
Share on other sites

weird. i can't edit my posts anymore...

@weapon, about the export, it isn't really the option i need. i just want to update svn but those options weren't available while i was taking the screenshot. it was just a general example i wanted to give. we can also take

Context Menu >> "Winrar">> "Add to zip" as the example.

by the way, i did read those articles you pointed me to. i think the tortoise command line parameters will serve my purpose but i am sure that sooner or later i will come across an issue where i have to use the windows context menus.

while i did get the idea of registry entries from the first article, i still don't know how to invoke them. googling didn't help much either. any further advices?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

When you right click a folder/file and choose a context menu entry, the only "magic" that is performed is inserting the path into a command line string.

Check out this program called ShellMenuView, it will list most of the context menu handlers on your system:

http://www.nirsoft.net/utils/shell_menu_view.html

For example, the handler for right-clicking on an mp3:

Open:

"C:\Program Files\Winamp\winamp.exe" "%1"

Enqueue:

"C:\Program Files\Winamp\winamp.exe" /ADD "%1"

The %1 is replaced with the filename you clicked on, thats all there is to it.

Edited by weaponx

Share this post


Link to post
Share on other sites

like appwiz just invokes the msiexec /y {reg uninstall key} command?

Neat! will read some more and experiment, and let you know if i was successful. thanks a lot for pointing me in the right direction.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

.... and simply write a function that takes a folder path as a parameter, none of this silly trying to automate explorer.exe.....

Little confused - how do I get the %1% value (which is the file/folder path) of the selected object ?? (I see similar command strings in the registry)

If this is possible, then I would love to write a keyboard shortcut which will copy the selected file/folder path to clipboard! - without having to open the context menu.

Edited by aria

Share this post


Link to post
Share on other sites

Little confused - how do I get the %1% value (which is the file/folder path) of the selected object ?? (I see similar command strings in the registry)

If this is possible, then I would love to write a keyboard shortcut which will copy the selected file/folder path to clipboard! - without having to open the context menu.

I've not fully understanding of your problem but you should take a look at this

ShellExecute($var,"","","Enqueue")

$var is the path....

Hope i helped..

SpecK


the finest Blues Jazz Rock by VL and SpecKtotallynoob.com tutorials about SysAdmins NetAdmins SecAdmins

Share this post


Link to post
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
Sign in to follow this  
Followers 0