C # network login

How to log on to the network to access a shared driver, for example, programmatically in C #? The same can be achieved either by attempting to open the shared resource via explorer, or by using the net use shell command.

+4
c # networking
source share
2 answers

P / Invoke calling WNetAddConnection2 will do the trick. Check here for more information.

[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 ); 
+5
source share

All Articles