Search code examples
pythonwindows-7-x643dsmax

How can I determine the location of 3d studio max using the registry using python?


I would like to locate 3d studio max using the windows registry using python. I am also not tied to a specific version.

I have seen several examples using _winreg but while I can see the desired key in regedit I am unable to access it via python.

The key I want is HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\3dsMax\14.0\MAX-1:409 with value Installdir.

The python script I am attempting to use is below.

from _winreg import *
t = OpenKey(HKEY_LOCAL_MACHINE, r"SOFTWARE\Autodesk\3dsMax\14.0\Max-1:409", 0, KEY_READ)

#try:
i = 0
while True:
    subkey = EnumKey(t, i)
    print subkey
    i += 1

The error I get back is as follows.

Traceback (most recent call last):
File "C:\testreg.py", line 2, in <module>
t = OpenKey(HKEY_LOCAL_MACHINE, r"SOFTWARE\Autodesk\3dsMax\14.0\Max-1:409", 0, KEY_READ)
WindowsError: [Error 2] The system cannot find the file specified

System Info:

Windows 7 Professional 64 bit

Tested with Python 2.5, 2.6 and 2.7 (32 bit versions of each)


Solution

  • If you are detecting a 64bit version of 3dsmax, you will have difficulty looking for it with a 32bit processes. 32bit processes on 64bit "convienently" have their registry hives substituted.

    if you wanted:

    hklm\SOFTWARE\autodesk\
    

    you are actually looking at:

    hklm\SOFTWARE\Wow6432Node\autodesk\
    

    Since 32bit applications existed before 64bit (on windows) there are lots of these shims that redirect in the registry and filesystem so 32bit programs get their keys and dlls while not requiring 64bit programs to name everthing differently (eg. c:\windows\system64, HKML\SOFTWARE64\ ).

    I think it's always easier to use 64bit processes to access 32bit not the other way around. But if that's not possible, this question might help you access the 64bit hive. Change 64bit Registry from 32bit Python