Announcement

Collapse
No announcement yet.

Verbinden mit einem Netzwerkpfad mittels WNetAddConnection3

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Verbinden mit einem Netzwerkpfad mittels WNetAddConnection3

    Hallo zusammen,

    ich versuche auf einem Skorpio X3, welches mit Windows Mobile 6.5 läuft, Dateien von einem Netzwerklaufwerk zu kopieren.

    Das Programm ist mit Visual Studio 2008 (C#) geschrieben. Die Funktionalität ist unter Visual Studio 2015 auf einem PC (Windows7) getestet und funktioniert (lediglich die coredll.dll ist gegen die mpr.dll getauscht).

    Ich bekomme als Fehlermeldung "Not Supported Exception", was eigentlich bedeuten sollte, dass die dll und der Entrypoint gefunden wurde...
    [highlight=c#]
    ...

    [StructLayout(LayoutKind.Sequential)]
    public class NETRESOURCE
    {
    public int dwScope;
    public int dwType;
    public int dwDisplayType;
    public int dwUsage;
    public string LocalName;
    public string RemoteName;
    public string Comment;
    public string Provider;
    }

    [DllImport("coredll.dll", EntryPoint = "WNetAddConnection3", CharSet = CharSet.Unicode, SetLastError = true)]
    public static extern int WNetAddConnection3(IntPtr hWndOwner, NETRESOURCE netResource, string password, string username, int flags);
    // [DllImport("coredll.dll", EntryPoint = "WNetCancelConnection2", CallingConvention = CallingConvention.Winapi, SetLastError = false)]
    // public static extern int WNetCancelConnection2(string lpName, Int32 dwFlags, bool fForce);

    static int ConnectNetworkResource(string server, string user, string password)
    {
    int dwResult;
    int result;

    NETRESOURCE netResource = new NETRESOURCE();
    netResource.dwScope = 0;
    netResource.dwType = 0; // RESOURCETYPE_ANY
    netResource.dwDisplayType = 0;
    netResource.dwUsage = 0;
    netResource.LocalName = null;
    netResource.RemoteName = "\\\\server\\pfad";
    netResource.Comment = null;
    netResource.Provider = null;
    try
    {
    dwResult = WNetAddConnection3(
    IntPtr.Zero
    ,netResource
    ,password
    ,user
    ,0x00000001);
    if (dwResult == 0)
    {
    result = 0;
    }
    else if (dwResult == 1219)
    {
    result = 0; // Die Verbindung besteht schon/noch
    }
    else
    {
    result = dwResult;
    }
    return result;
    }
    catch (Exception ex)
    {
    MessageBox.Show("Error: " + ex.Message, "Connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
    return 1;
    }
    }
    ...
    [/highlight]

    Jede Hilfe/Idee ist willkommen!

    Rainer
    Zuletzt editiert von gfoidl; 28.11.2015, 10:23. Reason: Code Formatierung
Working...
X