c# network login

2019-02-24 05:46发布

How do I perform a network login, to access a shared driver for instance, programmatically in c#? The same can be achieved by either attempting to open a share through the explorer, or by the net use shell command.

标签: c# networking
2条回答
forever°为你锁心
2楼-- · 2019-02-24 05:56

P/Invoke call to WNetAddConnection2 will do the trick. Look here for more info.

[DllImport("mpr.dll")]
 public static extern int WNetAddConnection2A
 (
      [MarshalAs(UnmanagedType.LPArray)] NETRESOURCEA[] lpNetResource,
      [MarshalAs(UnmanagedType.LPStr)] string lpPassword,
      [MarshalAs(UnmanagedType.LPStr)] string UserName, int dwFlags
 );
查看更多
登录 后发表回答