[英]How to copy file from network share in VB for an windows ce application
我正在使用vb.net做一个应用程序。
我需要的是从Windows ce设备访问计算机(win 8)并将一个文件复制到Windows ce设备。 我已经做了,但是现在我需要的是一种传递用户,密码和域的方法。 我已经研究并找到了使用System.Security.WindowsImpersonationContext的解决方案,所以我认为类似于Windows CE应用程序的工作方式。
很抱歉,如果您听不懂我说的话,但是我是编程新手,英语不是我的母语。
在此先感谢您的帮助
您可以使用SDF中Network
类的MapDrive
方法。 由于它非常简单,因此该方法的来源如下(我将其交给VB):
public static void MapDrive(IntPtr hwnd, string netRes, string shareName, string userName, string password)
{
NETRESOURCE NetRes = new NETRESOURCE();
NetRes.dwScope = RESOURCE_GLOBALNET | RESOURCE_REMEMBERED;
NetRes.dwType = RESOURCETYPE_DISK;
NetRes.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE;
NetRes.dwUsage = RESOURCEUSAGE_CONNECTABLE;
NetRes.lpRemoteName = Marshal2.StringToHGlobalUni(netRes);
NetRes.lpLocalName = Marshal2.StringToHGlobalUni(shareName);
NetRes.lpComment = IntPtr.Zero;
NetRes.lpProvider = IntPtr.Zero;
int ret = WNetAddConnection3(hwnd, NetRes, password, userName, 1);
if (ret != 0)
{
throw new System.ComponentModel.Win32Exception(ret, ((NetworkErrors)ret).ToString());
}
}
private class NETRESOURCE
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
public IntPtr lpLocalName;
public IntPtr lpRemoteName;
public IntPtr lpComment;
public IntPtr lpProvider;
}
[DllImport("coredll.dll")]
private static extern int WNetAddConnection3(
IntPtr hwndOwner,
NETRESOURCE lpNetResource,
string lpPassword,
string lpUserName,
int dwFlags);
const int RESOURCE_GLOBALNET = 0x00000002;
const int RESOURCE_REMEMBERED = 0x00000003;
const int RESOURCETYPE_DISK = 0x00000001;
const int RESOURCEDISPLAYTYPE_SHARE = 0x00000003;
const int RESOURCEUSAGE_CONNECTABLE = 0x00000001;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.