1

I'm writing a cross-platform Python application that acts as a frontend for DOSBox. It needs to call the DOSBox executable with a number of command line arguments. I don't want to hardcode a specific path to DOSBox because it might depend on where the user has installed it.

On Linux, I can simply do:

import subprocess
subprocess.run(['dosbox'] + args)

On Windows, however, I currently use the following code:

import subprocess
subprocess.run(['C:\PROGRAM FILES(X86)\DOSBOX\DOSBOX.EXE'] + args)

Which seems awfully specific, and doesn't work if DOSBox is installed in, for instance, the %LOCALAPPDATA%\Programs folder. Instead, I'd like to query the registry for the correct entry point to a program that identifies as "DOSBox". How can I do that in Python?

(NB: I have also asked this sibling question for macOS.)

Jaap Joris Vens
  • 3,382
  • 2
  • 26
  • 42

1 Answers1

2

You will probably have to use winreg to find where dosbox is installed

I'm basing my answer on this answer

import winreg
reg_conn = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
#  note that i dont have dosbox so you may have to double check the capitalization
key = winreg.OpenKey(reg_conn , r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DOSBox") 
res_tuple = winreg.QueryValueEx(key, 'InstallLocation')

res_tuple[0] should be the directory of where dosbox is installed, but as i've mentioned I do not have it installed so you should double check that InstallLocation is the correct key

This will probably not work for the portable version of dosbox because it probably doesnt have any registry keys

Nullman
  • 4,179
  • 2
  • 14
  • 30
  • Although this _is_ the correct answer, it doesn't work because there is no `DOSBox` key in the `CurrentVersion\Uninstall` registry, even when DOSBox is installed. I guess I'll have to stick to my original approach. – Jaap Joris Vens Jan 02 '21 at 12:32
  • @hedgie its installed and there are no keys at all? try maybe in `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths` – Nullman Jan 02 '21 at 14:07
  • Yes, it's installed using the regular installer from dosbox.com – Jaap Joris Vens Jan 02 '21 at 20:51