[英]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. 我有一个ac#UWP应用程序,我打算在带有Windows 10 IoT核心的Raspberry PI上运行。 The problem I have is when I try to connect to a UNC share to copy some files. 我遇到的问题是当我尝试连接到UNC共享来复制某些文件时。
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(@"\\\\share\\folder");
在本地运行应用程序时,我可以使用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." 在RPi上运行时,收到的错误是:“系统找不到指定的文件。”
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: 我尝试过的:
await StorageFolder.GetFolderFromPathAsync(@"\\\\share\\folder");
("The system cannot find the file specified.") (“该系统找不到指定的文件。”) net use "\\\\share\\folder" "password" /USER:"user"
works and unc can be browsed 使用PowerShell与net use "\\\\share\\folder" "password" /USER:"user"
工作,unc可以浏览 WNetAddConnection2
as in Prevent WNetAddConnection2 class which allows prohibited user to access shared folder 尝试使用WNetAddConnection2
如在Prevent WNetAddConnection2类中允许禁止用户访问共享文件夹 WNetUseConnection
with both user prompt and without (neither works) 尝试使用WNetUseConnection
同时提供用户提示和不使用( WNetUseConnection
) 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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.