以编程方式获取 Samba 共享卷 ID

Getting Samba share volume id programmatically

我需要知道在 c++ 中与 smb 共享的卷的序列号。我使用 GetVolumeInformation 从 Windows 获取此 ID。在 Linux 中,我使用

从 bash 中得到相同的结果

$ smbclient '\<ip>\<share>' -c volume

如何在 C++ 中获得相同的值?

您可以使用 samba 包 link 您的代码,并模仿 smbclient 工具正在做的事情。您可以在这里找到它:https://github.com/samba-team/samba/blob/master/source3/client/client.c#L4423

但简单而合理的做法是直接从您的程序调用此 shell 命令并使用 popen 读取输出。看一个例子 这里:

How do I execute a command and get the output of the command within C++ using POSIX?