I am new to python. I am writing an automation script to right click a text file and then click on a Context Menu Item. Here I am using win32api ans win32con. I am unable to locate a file using win32api.SetCursorPos((x,y)). Is there a way to set cursor on a file without specifying x,y co-ordinates?
I think, you should append your context menu in windows (by regedit or by menu) and call your script with the filename as argument.
check this : Add menu item to windows context menu only for specific filetype
You can then get it with sys.argv or use the optparse module
Related
I'm programming on Excel-Visual Basic with a Mac, I need to charge a dll but I don't know how to specify the total path of the file, and I don't know how to find it.
For example: on Windows it works by using "C:/ ..." and separating the following documents by /.
Right click on the file in Finder
If you then hold the option button on your keyboard the Copy {filename} option in the context menu turns into Copy {filename} as Pathname
Click on that while still holding the option key and the path of the file is in your clipboard
I'm trying to create a shell command to open a given directory in the Explorer folder that the command is executed from.
I would add it as an entry to the right-click menu in regedit (HKCR\Directory\background\shell), but I can't figure out how to actually make the folder open in the current Explorer instance. (like the "open file location" option).
The open file location feature (COpenFileLocationMenu in shell32) is a shell extension, not a simple static command in the registry. COpenFileLocationMenu also implements IObjectWithSite.
When the IContextMenu::InvokeCommand method in COpenFileLocationMenu is called, it calls IUnknown_QueryService(..., SID_SInPlaceBrowser, IShellBrowser) on its site so it can navigate the Explorer window with IShellBrowser.
Background menu items receive the folder location in IShellExtInit::Initialize and normal menu items can use IShellBrowser::QueryActiveShellView to get the view and then find the current location...
If you don't want to write a shell extension then you have to settle for the scriptable ShellWindows object but you would have to do some guessing to find the correct window, perhaps by PInvoke'ing GetForegroundWindow from Powershell.
Why can't I pass the location of my right click to a program as an argument if I am not right clicking on an object?
My Test set up:
Windows 10, I have DebugViewer running and my program something.exe will output any arguments it receives to debug.
I set up these registry entries in the:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\TestYo2]
#="Directory Test"
[HKEY_CLASSES_ROOT\Directory\Background\shell\TestYo2\command]
#="c:\\something.exe %1"
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\txtfile\shell\Try This]
#="Txt Menu"
[HKEY_CLASSES_ROOT\txtfile\shell\Try This\command]
#="c:\\something.exe %1"
RESULTS:
When I right click on a text file and select my "Txt Menu" from the context menu fires up my program and passes it the file path to the text file. The location of the text file I right clicked on is printed to debug.
If I right click on the background of an opened directory and select my "Directory Test" this message is displayed:
This file does not have a program associated with it for performing this action. Please install a program or, if one is already installed, create an association in the Default Programs control panel.
My program is never fired up.
What gives?
So the solution is this:
Add a new key called NoWorkingDirectory and leave the data blank.
In the command line %1 becomes a %V
Now when I right click the background and select my menu item, it launches my program and passes to the program an argument containing the location of where the right click just took place. done.
found it via this post: Windows shell add item to context menu when click on blank part of folder
I am creating a directory synch application in java programming application. Now i want to add share option when user right click with in a specific directory, and want to open an dynamic url on clicking that new option. Can anyone help me to find any good solution. Can anyone provide me Registry Script For this task.
An msdn resource on Extending Shortcut Menus will be good for you.
Anyway, I'd like to introduce my own "minimal" example. This opens a gnuplot's wgnuplot terminal at the right-clicked directory after choosing "Open gnuplot here" shortcut.
You can add keys into HKEY_CLASSES_ROOT\Directory\shell. I added HKEY_CLASSES_ROOT\Directory\shell\gnuplot with string (name: (Default)) Open gnuplot here, provided an icon string with the program's icon path, a LegacyEnable empty string and a command key that windows have to execute when clicking. You can reach the right clicked directory name with %V (You can find out more special variables on this Q&A thread at SU). Here's the code that creates the structure:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\gnuplot]
#="Open gnuplot here"
"Icon"="\"C:\\Windows\\icons\\wgnuplot.ico\""
"LegacyEnable"=""
[HKEY_CLASSES_ROOT\Directory\shell\gnuplot\command]
#="\"C:\\Users\\Cron\\Documents\\egyetem\\gnuplot\\bin\\pgnuplot.exe\" -e \"cd '%V'\" -persist"
I have OpenFileFialog realized in my Windows Forms application, but when I use Open With in file context menu, or add my item in context menu with command like "myapp.exe %1" it just opens application. Need I to do anything else to realize it?
This does nothing more than pass a filename as the first argument to your program. Just having an OpenFileDialog is completely irrelevant to that. You need to examine command-line arguments at startup and decide that you might want to open a file if one is given.