Netzwerk per Programm



  • Ich brauche nochmal Hilfe,

    ich komme mit der API WNetAddConnection2 nicht weiter.

    Das funktioniert:
    ProcessStartInfo ^test=gcnew ProcessStartInfo("net"," use z: \\\comp1\\c$ test1 /user:testuser");
    test->WindowStyle=ProcessWindowStyle::Hidden;
    Process::Start(test);

    Das gleiche mit der API liefert immer Error 487:

    value struct net_resource{
    UInt32 dwScope;
    UInt32 dwUsage;
    UInt32 dwType;
    String ^lpLocalName;
    String ^lpRemoteName;
    UInt32 lpProvider;
    };

    [DllImport("Mpr.dll")]
    extern "C" UInt32 WNetAddConnection2(net_resource %,String,String,Int32);

    net_resource %resource= *(gcnew net_resource);
    resource.dwScope=RESOURCE_GLOBALNET;
    resource.dwUsage=RESOURCEUSAGE_CONNECTABLE;
    resource.dwType=RESOURCETYPE_ANY;
    resource.lpLocalName="z:";
    resource.lpRemoteName="\\\comp1\\c$";
    resource.lpProvider=NULL;

    String ^password="test1";
    String ^username="testuser";
    DWORD test=WNetAddConnection2(resource,password,username,CONNECT_UPDATE_PROFILE);

    Aus stdafx.h:

    #include <windows.h>
    #pragma comment (lib, "mpr.lib")
    #pragma comment (lib, "Netapi32.lib")
    #include <winnetwk.h>
    #include <stdio.h>
    #include <tchar.h>

    Warum geht das nicht?




Anmelden zum Antworten