import _winreg as wr
# Just picked three formats - feel free to substitute or extend as needed
videoFormats = ('.wmv', '.avi', '.mpeg')
#Results written to this list
userOpenPref = []
for i in videoFormats:
subkey = ("Software\\Microsoft\\Windows\\CurrentVersion" +
"\\Explorer\\FileExts\\" + i + "\\UserChoice")
explorer = wr.OpenKey(wr.HKEY_CURRENT_USER, subkey)
try:
i = 0
while 1:
# _winreg.EnumValue() returns a tuple:
# (subkey_name, subkey_value, subkey_type)
# For this key, these tuples would look like this:
# ('ProgID', '<default-program>.AssocFile.<file-type>', 1).
# We are interested only in the value at index 1 here
userOpenPref.append(wr.EnumValue(explorer, i)[1])
i += 1
except WindowsError:
print
explorer.Close()
print userOpenPref
根据上面的评论,看起来你决定朝另一个方向发展。你的问题让我很好奇,所以我四处打猎。
文件关联存储在Windows注册表中。通过python访问Windows注册表信息的方法是使用_winreg模块(在2.0和更高版本中可用)。当前用户的单个文件关联信息将存储在名为以下名称的子项中:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.wmv\UserChoices
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mpeg\UserChoices
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.avi\UserChoices
etc,etc用于您要查找的任何特定文件格式。
下面是我编写的一个小示例脚本,用于访问此信息并将其存储为列表:
输出:
[u'WMP11.AssocFile.WMV', u'WMP11.AssocFile.avi', u'WMP11.AssocFile.MPEG']
使用WMP11=Windows Media Player 11
希望这对你有帮助。
资料来源:
{a2}
相关问题 更多 >
编程相关推荐