gpt4 book ai didi

winapi - 如何为网络路径使用 CreateFile API 函数?

转载 作者:行者123 更新时间:2023-12-01 10:58:27 28 4
gpt4 key购买 nike

我遇到了 C 盘的 CreateFile API。它工作正常。但是,当我尝试使用网络共享路径时,它会引发错误。

private void GetRootHandle()
{
string vol = string.Concat(@"\\192.168.1.24\share1");
_changeJournalRootHandle = PInvokeWin32.CreateFile(vol,
PInvokeWin32.GENERIC_READ | PInvokeWin32.GENERIC_WRITE,
PInvokeWin32.FILE_SHARE_READ | PInvokeWin32.FILE_SHARE_WRITE,
IntPtr.Zero,
PInvokeWin32.OPEN_EXISTING,
0,
IntPtr.Zero);
if (_changeJournalRootHandle.ToInt32() == PInvokeWin32.INVALID_HANDLE_VALUE)
{
throw new IOException("CreateFile() returned invalid handle",
new Win32Exception(Marshal.GetLastWin32Error()));
}
}

谁能告诉我如何为这个 API 函数使用共享路径

最佳答案

I am getting Access is denied exception

那是因为它不是一个文件。通过 使用 CreateFile() 获得成功,它只是没有必要。使用常规的 .NET 类,如 DirectoryInfo.EnumerateFiles() 来枚举文件,使用 FileStream 打开它们。如果需要调用 GetFileInformationByHandle(),请使用 FileStream.SafeFileHandle 属性。

关于winapi - 如何为网络路径使用 CreateFile API 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16495898/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com