简体   繁体   中英

Python script won't run from the context menu

[Submitted to superuser two days ago, but nobody could answer it, so reposting here.]

Working on the basis of this post (and this follow-up post ), I've tried adding a python script (which I've added to the path and so on, so that I can run it from the command line everywhere in the system) to the context menu, like this:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\get_abs]
@="&Get Abstracts"
"Icon"="%SystemRoot%\\System32\\shell32.dll,71"

[HKEY_CLASSES_ROOT\Directory\Background\shell\get_abs\command]
@="C:\\cmdtools\\get_abs.py"

However, I get a strange error message when I try to run it.

在此处输入图片说明

To be clear, I have successfully run this script from the command line (using powershell, in case it matters) in the folder in which I'm trying to run it from the context menu.

Python scripts aren't natively executable by Windows; it's complaining that you didn't specify an .exe file. That's easy though, you just specify python.exe . Follow that up with the path to your script and then a %1 -- this is a placeholder for the path to the clicked file. To allow your command to work with paths with spaces in them, surround the %1 with quote marks. Putting it all together, we get:

C:\path\to\python.exe C:\path\to\your\script.py "%1"

BTW, a handy utility for managing context menus is Fast Explorer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM