windows 从python在windows上查找程序的安装目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7468061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Finding installation directory of a program on windows from python
提问by Boris Gorelik
A python program needs to find the installation location of openoffice.org, which is installed on a Windows XP computer. What is the best way to do this?
一个python程序需要找到openoffice.org的安装位置,它安装在Windows XP电脑上。做这个的最好方式是什么?
回答by rocksportrocker
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). Then you can query this path as I did it once to find the home directory of R:
您可以_winreg
在 windows 上使用该模块:首先在注册表中找出路径(例如启动regedit.exe
并使用其查找功能)。然后你可以查询这个路径,就像我曾经做过的那样找到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