簡體   English   中英

如何從Windows CE應用程序的VB中的網絡共享中復制文件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM