Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# network login

Tags:

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.

like image 484
eulerfx Avatar asked Oct 01 '08 16:10

eulerfx


1 Answers

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
 );
like image 81
Vivek Avatar answered Sep 30 '22 13:09

Vivek