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.)

1 Answer 1

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

3
  • 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. Jan 2, 2021 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 2, 2021 at 14:07
  • Yes, it's installed using the regular installer from dosbox.com Jan 2, 2021 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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