В общем, делаю так:
| Код | [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("mpr.dll")] static extern int WNetAddConnection2( NETRESOURCE netResource, string password, string username, int flags);
NETRESOURCE rc = new NETRESOURCE(); rc.dwType = 0x00000000; rc.RemoteName = @"\\hostname"; rc.Provider = null; int ret = WNetAddConnection2(rc, "pass", "username", 0);
|
либо так:
| Код | [StructLayout(LayoutKind.Sequential)] public struct 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("mpr.dll")] static extern int WNetAddConnection2(ref NETRESOURCE netResource, string password, string username, int flags);
NETRESOURCE rc = new NETRESOURCE(); rc.dwType = 0x00000000; rc.RemoteName = @"\\hostname"; rc.Provider = null; int ret = WNetAddConnection2(ref rc, "pass", "username", 0);
|
Все время возвращает ошибку, либо 67 (The network name cannot be found), либо 1200 (The specified device name is invalid). Хотя в С++ все работает...
Что я делаю не так? Ткните носом пжалста! |