How to access Network Share from Raspberry Pi running IoT Core in UWP app

I have ac# 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.

When running the app locally I can just use await StorageFolder.GetFolderFromPathAsync(@"sharefolder"); 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...

What I've tried:

  • Share has permissions for everyone and can be accessed without credentials
  • Network share computer firewall is off.
  • manifest has the private networks, enterprise auth, and Internet (both) setup (assuming okay as works locally).
  • await StorageFolder.GetFolderFromPathAsync(@"sharefolder"); ("The system cannot find the file specified.")
  • using powershell with net use "sharefolder" "password" /USER:"user" works and unc can be browsed
  • Tried using WNetAddConnection2 as in Prevent WNetAddConnection2 class which allows prohibited user to access shared folder
  • Tried using WNetUseConnection with both user prompt and without (neither works)
  • FolderPicker or FileOpenPicker but these seem to be disabled for IoT Core (https://ms-iot.github.io/content/en-US/win10/UnavailableApis.htm).
  • Thanks in advance,

    Paul.


    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();
    }
    
    链接地址: http://www.djcxy.com/p/44180.html

    上一篇: 如何在Visual Studio 2010中使用Boost

    下一篇: 如何在UWP应用程序中使用运行IoT Core的Raspberry Pi访问网络共享