Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a short python script that is set as my default browser in the registry. It will choose to launch IE or Firefox based on the URL (Some work sites only function in IE). In the past, I just used a full path to the python installation to launch it, but this recently broke due to a change in the python install location (it is now bundled with our project files, so it may change more frequently). The path should be updated when it moves, so simply depending on the current environment to find python should be sufficient.

This is the old registry command entry:

[HKEY_CLASSES_ROOT\RRBrowserChooserURL\shell\open\command]

@="\"C:\\Python26\\python.exe\" \"C:\\browser_chooser.pyw\" \"%1\""

Here's the best working option I have come up with so far:

[HKEY_CLASSES_ROOT\RRBrowserChooserURL\shell\open\command]

@="\"C:\\Windows\\System32\\cmd.exe\" \"/c\" \"C:\\browser_chooser.pyw\" \"%1\""

However, this briefly pops up the command window when opening a link. I'd like to avoid that.

Without rewriting my script in another language and compiling it into an executable I can reference directly, is there a good way to get this to execute without knowing the path?

share|improve this question

3 Answers 3

You would have to add the Python path to the system variable PATH or create a new system variable that is something like PYTHONDIR and have that point to the Python directory and then call the python.exe with %PYTHONDIR%\python.exe

PS. Why don't you use the Firefox Add-On IE Tabs?

share|improve this answer
    
I solve the IE problem with Google Chrome Frame - It lets (l)users continue to use IE, but will transparently render a site within IE using the Chrome engine whenever the site asks for it. My websites demand this plugin of my IE users. A clever solution to a horrible problem. –  Doc Nov 15 '12 at 23:12
    
The python install directory is in PATH, which is why using cmd.exe works. Without a full path to the exe though, it can't be found. I will try IE tabs when I'm at the office tomorrow. –  RabbleRooster Nov 16 '12 at 3:05
    
@RabbleRooster, that's strange because it works for me. I just created a test on my system doing what you are doing and it worked. –  Sane Nov 16 '12 at 16:49
    
What was the syntax that leveraged the PATH? This doesn't work for me: @="\"python.exe\" \"C:\\browser_chooser.pyw\" \"%1\"" –  RabbleRooster Nov 16 '12 at 20:32
    
@="python.exe \"c:\\test.py\" \"%1\"" –  Sane Nov 16 '12 at 22:16

Can you use a .lnk file (i.e., a filesystem shortcut) in the open\command field in the registry?  If so, create a shortcut that runs your cmd /c command and has the “Run” control set to “Minimized”:

shortcut properties window with Run = Minimized circled

cmd.exe will still run, but it won’t pop up a window; it’ll only display a taskbar button.

share|improve this answer

If compiling without rewriting is an option, you can compile your python script into an exe with py2exe or pyinstaller- it'll compile it into a self contained exe and dlls you can use to run the application on its own with its own copy of python as a dll.

share|improve this answer
1  
py2exe is pretty outdated. Probably better to use pyinstaller –  ernie Nov 15 '12 at 23:52
    
ooh, wasn't aware of that. Edited it into my answer, thanks –  Journeyman Geek Nov 15 '12 at 23:54
    
Anything is an option; this is a convenience tool. If I couldn't find a better option, I was going to go this route. This script had been passed around the office a bit, and I liked that people could edit it easily to modify the rules if needed. –  RabbleRooster Nov 16 '12 at 3:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.