【问题标题】:Python: Get volume serial number from lnk file?Python:从 lnk 文件中获取卷序列号?
【发布时间】:2013-10-31 12:30:09
【问题描述】:

我有一个 lnk 文件(快捷方式文件)。我使用了一个名为 Windows LNK Parsing Utility (lp) 的工具来找出原始文件所在的卷序列号。所以我想在 python 中创建一个执行相同操作的脚本。

我发现 win32api 模块应该有帮助,所以这是我的代码:

import win32api, win32con, win32security # win32api main mod, other modules to get SID

path = ('C:\Users\Si\Desktop\Files\Shortcut to Pictures.lnk')

print win32api.GetVolumeInformation(path)


Error says:

Traceback (most recent call last):
File "C:\Users\Si\Desktop\Files\test.py", line 3, in <module> pywintypes.error: (123, 'GetVolumeInformation', 'The filename, directory name, or volume label syntax is incorrect.')

是否有另一种(也许更好?)方法可以做到这一点?

谢谢

【问题讨论】:

    标签: python volume serial-number


    【解决方案1】:

    来自文档

    tuple = GetVolumeInformation(path)
    
    Returns information about a file system and colume whose root directory is specified.
    

    可能

    win32api.GetVolumeInformation('C:\\')
    

    【讨论】:

    • 它适用于 'C:\\' 但不适用于诸如 "C:\\file.txt" 之类的文件
    • 从文件路径中提取根目录并使用它而不是完整路径。
    猜你喜欢
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 2012-06-15
    • 2010-09-28
    • 2010-10-06
    • 2020-09-21
    • 1970-01-01
    • 2019-12-24
    相关资源
    最近更新 更多