本文介绍了如何从在 UWP 应用中运行 IoT Core 的 Raspberry Pi 访问网络共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 c# UWP 应用程序,我打算在带有 Windows 10 IoT Core 的 Raspberry PI 上运行.我遇到的问题是当我尝试连接到 UNC 共享以复制一些文件时.

I have a c# UWP app that I'm intending to run on a Raspberry PI with Windows 10 IoT Core. The problem I have is when I try to connect to a UNC share to copy some files.

网络只是具有本地用户凭据的家庭网络,共享位于同一网络上的另一台计算机上.

The network is just a home network with local user credentials, share is on another computer on the same network.

在本地运行应用程序时,我可以使用 await StorageFolder.GetFolderFromPathAsync(@"\\share\folder"); 连接到共享,这工作正常,我假设这是因为我使用的凭据保存在本地计算机上.在 RPi 上运行时,收到的错误是:系统找不到指定的文件."

When running the app locally I can just use await StorageFolder.GetFolderFromPathAsync(@"\\share\folder"); to connect to the share and this works fine, I'm assuming this is because the credentials I'm using are saved on the local machine. When ran on the RPi the error received is: "The system cannot find the file specified."

有没有人对我如何连接到这个驱动器有任何想法,在这个阶段我愿意做任何事情来让它工作......

Does anyone have any ideas on how I would connect to this drive, I'm game for anything at this stage to get it to work...

我尝试过的:

  1. 共享对所有人都有权限,无需凭据即可访问
  2. 网络共享计算机防火墙已关闭.
  3. manifest 具有专用网络、企业身份验证和互联网(两者)设置(假设本地工作正常).
  4. await StorageFolder.GetFolderFromPathAsync(@"\\share\folder");(系统找不到指定的文件.")
  5. 使用 powershell 和 net use "\\share\folder" "password"/USER:"user" 工作并且可以浏览 unc
  6. 尝试使用 WNetAddConnection2,如 阻止允许被禁止用户访问共享文件夹的 WNetAddConnection2 类
  7. 尝试使用 WNetUseConnection 与用户提示和不使用(均无效)
  8. FolderPicker 或 FileOpenPicker 但这些似乎对 IoT Core 禁用 (https://ms-iot.github.io/content/en-US/win10/UnavailableApis.htm).
  1. Share has permissions for everyone and can be accessed without credentials
  2. Network share computer firewall is off.
  3. manifest has the private networks, enterprise auth, and Internet (both) setup (assuming okay as works locally).
  4. await StorageFolder.GetFolderFromPathAsync(@"\\share\folder"); ("The system cannot find the file specified.")
  5. using powershell with net use "\\share\folder" "password" /USER:"user" works and unc can be browsed
  6. Tried using WNetAddConnection2 as in Prevent WNetAddConnection2 class which allows prohibited user to access shared folder
  7. Tried using WNetUseConnection with both user prompt and without (neither works)
  8. FolderPicker or FileOpenPicker but these seem to be disabled for IoT Core (https://ms-iot.github.io/content/en-US/win10/UnavailableApis.htm).

提前致谢,

保罗.

推荐答案

您是否尝试过模拟?这是我在我的一个项目中使用的:

Have you tried impersonation yet? Here is what I use in one of my projects:

[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

private void Impersonate(Enum domainName, string userName, string password)
{
    IntPtr _tokenHandle = IntPtr.Zero;
    int Logon32_Provider_Default = 0;
    int Logon32_Logon_Interactive = 2;

    bool userSuccess = LogonUser(userName, domainName.ToString(), password, Logon32_Logon_Interactive, Logon32_Provider_Default, ref _tokenHandle);

    if (!userSuccess)
    {
        throw new Win32Exception(Marshal.GetLastWin32Error());
    }

    WindowsImpersonationContext _impersonatedUser = new WindowsIdentity(_tokenHandle).Impersonate();
}

这篇关于如何从在 UWP 应用中运行 IoT Core 的 Raspberry Pi 访问网络共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 22:57