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.
<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();
}