简体   繁体   English

从python在Windows上查找程序的安装目录

[英]Finding installation directory of a program on windows from python

A python program needs to find the installation location of openoffice.org, which is installed on a Windows XP computer. python程序需要找到openoffice.org的安装位置,该安装位置安装在Windows XP计算机上。 What is the best way to do this? 做这个的最好方式是什么?

You can use the _winreg module on windows: First find out the path in the registry (eg starting regedit.exe and using its find function). 您可以在Windows上使用_winreg模块:首先找出注册表中的路径(例如,启动regedit.exe并使用其find函数)。 Then you can query this path as I did it once to find the home directory of R: 然后你可以查询这条路径,就像我做了一次找到R的主目录:

key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\R-core\\R")
value =  _winreg.QueryValueEx(key, "InstallPath")[0]

ADDED : 增加

If you are not familiar with the windows regstry: have a look at http://en.wikipedia.org/wiki/Windows_Registry 如果您不熟悉windows regstry:请查看http://en.wikipedia.org/wiki/Windows_Registry

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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