在.net框架内有没有办法检查两个不同的共享文件夹是否实际上指向同一个物理目录? Windows 中的目录是否有某种唯一标识符? Google-fu 让我失望了。
(我的意思是,除了向一个文件写入一个临时文件并查看它是否出现在另一个文件中)
编辑:我想我已经发现了我需要的东西,感谢布罗迪让我在 System.Management 中指出了正确的方向命名空间。
Is there a way, within the .net framework, to check to see if two different shared folders are actually pointing to the same physical directory? Do directories in Windows have some sort of unique identifier? Google-fu is failing me.
(I mean, aside from writing a temp file to one and seeing if it appears in the other)
Edit: I think I've discovered what I need,with thanks to Brody for getting me pointed in the right direction in the System.Management namespace.
发布评论
评论(4)
如果您不使用 WMI,则非托管调用为 NetShareEnum 服务器名称为 NULL(本地计算机),级别为 502 以获得 SHARE_INFO_502 结构。 本地路径在shi502_path中。
P/Invoke 信息一如既往,在 pinvoke.net 结束。
If you don't go WMI, the unmanaged call is NetShareEnum with a servername of NULL (local computer) and a level of 502 to get a SHARE_INFO_502 struct. The local path is in shi502_path.
P/Invoke info, as always, is over at pinvoke.net.
您可以使用 System.Management 命名空间检查共享定义本身,但它并不容易使用。
它开始了类似的事情
,之后情况变得更糟。 我已经用它来创建共享。 希望您可以使用它来进行每个共享的路径并进行比较。
You can examine the share definition itself by using the System.Management namespace but it is not easy to use.
it starts something like
And it gets much worse after that. I have used it to create a share. Hopefully you can use it to the path for each share and compare.
我认为 .NET 框架没有提供比较 2 个目录所需的信息......
您必须采取不受管理的方法。 我就是这样做的:
有效! 希望这可以帮助。
干杯。
I think the .NET framework doesn't provide the information you need for comparing 2 directories ...
You have to take an unmanaged approach. This is how I did it:
It works! Hope this helps.
Cheers.
我相信使用 WMI 查询将满足我需要做的事情:
并且 Path 属性将为我提供共享的物理路径,我可以用它来比较两个共享。
I believe using WMI queries will take care of what I need to do:
And the Path attribute will give me the physical path of the share, which I can use to compare the two shares.