我正在使用vb.net做一个应用程序。
我需要的是从Windows ce设备访问我的计算机(win 8)并将一个文件复制到Windows ce设备。我已经做了,但是现在我需要的是一种传递用户,密码和域的方法。我已经研究并找到了使用System.Security.WindowsImpersonationContext的解决方案,所以我认为类似于Windows CE应用程序的某些解决方案。
很抱歉,如果您听不懂我说的话,但是我是编程新手,英语不是我的母语。
在此先感谢您的帮助
您可以使用SDFMapDrive
中的Network
类的方法。由于它非常简单,因此该方法的来源如下(我将其交给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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句