Vb.net 如何在VB中为windows ce应用程序从网络共享复制文件
我正在用vb.net做一个应用程序 我需要的是从windows ce设备访问我的计算机win 8,并将一个文件复制到windows ce设备。 我已经这样做了,但是我现在需要的是一种传递用户、密码和域的方法。 我已经研究并找到了一些使用System.Security.WindowsImpersonationContext的解决方案,因此我认为类似的解决方案可以在windows ce应用程序中使用 对不起,如果你不明白我说的话,但我是编程新手,英语不是我的母语 提前感谢您的帮助您可以使用SDF中网络类的MapDrive方法。因为它非常简单,所以该方法的源代码如下,我将其留给您,让您将其发送到VB:Vb.net 如何在VB中为windows ce应用程序从网络共享复制文件,vb.net,windows-ce,impersonation,Vb.net,Windows Ce,Impersonation,我正在用vb.net做一个应用程序 我需要的是从windows ce设备访问我的计算机win 8,并将一个文件复制到windows ce设备。 我已经这样做了,但是我现在需要的是一种传递用户、密码和域的方法。 我已经研究并找到了一些使用System.Security.WindowsImpersonationContext的解决方案,因此我认为类似的解决方案可以在windows ce应用程序中使用 对不起,如果你不明白我说的话,但我是编程新手,英语不是我的母语 提前感谢您的帮助您可以使用SDF中网
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;
非常感谢。帮了我很多忙