从python查找Windows上程序的安装目录 [英] Finding installation directory of a program on windows from python

查看:363
本文介绍了从python查找Windows上程序的安装目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python程序需要找到Windows XP计算机上安装的openoffice.org的安装位置.最好的方法是什么?

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?

推荐答案

您可以在Windows上使用_winreg模块:首先在注册表中查找路径(例如,启动regedit.exe并使用其find函数).然后,您可以像我一样查询此路径以找到R的主目录:

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:

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

添加:

如果您不熟悉Windows注册表,请查看 http://en.wikipedia .org/wiki/Windows_Registry

If you are not familiar with the windows regstry: have a look at http://en.wikipedia.org/wiki/Windows_Registry

这篇关于从python查找Windows上程序的安装目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆