woezelmann
Mitglied
Hallo Leute!
Vor einiger Zeit hab ich es (tutorials.de sei Dank) geschaft, eine Verbindung mit einem freigegeben Laufwerk im Netzwerk aufzubauen. Gestern gings auch alles noch ohne weiteres, doch als ich heute meinen Rechner gestartet habe, gings dann nicht mehr
!
Ich bin mir 100%ig sicher, dass ich am Code nichts geändert habe, sitz jetzt schon seit 2 Stunden dran, komm aber nicht drauf, was los ist.
Mein Code sieht so aus:
Ich bekomme unterschiedliche errorcodes, abhängig davon, was für einen Wert ich lpLocalName gebe:
lpLocalName = null; -> 487: Attempt to access invalid address.
lpLocalName = ""; -> 67: The network name cannot be found.
lpLocalName = "H:" -> The specified network provider name is invalid.
Wie gesagt, gestern ging das Ganze noch ohne Probleme.
Bitte bitte, helft mir
Vor einiger Zeit hab ich es (tutorials.de sei Dank) geschaft, eine Verbindung mit einem freigegeben Laufwerk im Netzwerk aufzubauen. Gestern gings auch alles noch ohne weiteres, doch als ich heute meinen Rechner gestartet habe, gings dann nicht mehr

Ich bin mir 100%ig sicher, dass ich am Code nichts geändert habe, sitz jetzt schon seit 2 Stunden dran, komm aber nicht drauf, was los ist.
Mein Code sieht so aus:
Code:
private const int CONNECT_INTERACTIVE = 0x00000008;
private const int CONNECT_PROMPT = 0x00000010;
private const int RESOURCETYPE_ANY = 0x0;
[DllImport("mpr.dll", EntryPoint = "WNetAddConnection2W",
CharSet = CharSet.Unicode)]
private static extern int WNetAddConnection2(
ref NETRESOURCE lpNetResource, string lpPassword, string lpUsername, Int32 dwFlags);
public void addConn()
{
NETRESOURCE ConnInf = new NETRESOURCE();
ConnInf.dwScope = 0;
ConnInf.dwType = RESOURCETYPE_ANY;
ConnInf.dwDisplayType = 0;
ConnInf.dwUsage = 0;
ConnInf.lpLocalName = null;
ConnInf.lpRemoteName = "\\\\192.168.199.128\\sammelverzeichnis";
ConnInf.lpComment = null;
ConnInf.lpProvider = null;
int conn = WNetAddConnection2(ref ConnInf, "test", "test",
CONNECT_INTERACTIVE | CONNECT_PROMPT);
}
#region Nested type: NETRESOURCE
[StructLayout(LayoutKind.Sequential)]
internal struct NETRESOURCE
{
public int dwDisplayType;
public int dwScope;
public int dwType;
public int dwUsage;
[MarshalAs(UnmanagedType.LPWStr)] public string lpComment;
[MarshalAs(UnmanagedType.LPWStr)] public string lpLocalName;
[MarshalAs(UnmanagedType.LPWStr)] public string lpProvider;
[MarshalAs(UnmanagedType.LPWStr)] public string lpRemoteName;
}
#endregion
Ich bekomme unterschiedliche errorcodes, abhängig davon, was für einen Wert ich lpLocalName gebe:
lpLocalName = null; -> 487: Attempt to access invalid address.
lpLocalName = ""; -> 67: The network name cannot be found.
lpLocalName = "H:" -> The specified network provider name is invalid.
Wie gesagt, gestern ging das Ganze noch ohne Probleme.
Bitte bitte, helft mir
