1. By executing the command, there will be a CMD window flashing:
public void Get_Share (string remotepath, string localpath, string username, string password) {Process.Start ( "net", "use" localpath "" remotepath "" password "/ user:" username);}
Public void brek_share (string localpath) {process.start ("net", "use" localpath "/ delete");}
2. Call the API function of Window:
[DllImport ( "mpr.dll")] public static extern int WNetAddConnection2A (NETRESOURCE [] lpNetResource, string lpPassword, string lpUserName, int dwFlags); [DllImport ( "mpr.dll")] public static extern int WNetCancelConnection2A (string sharename, INT dwflags, int force;
public int GetShare (string remotepath, string localpath, string username, string password) {try {NETRESOURCE [] share_driver = new NETRESOURCE [1]; share_driver [0] .dwType = 1; share_driver [0] .lpLocalName = localpath; share_driver [ 0] .lpremotename = RemotePath;
Breakshare (localpath); int RET = WNETDCONNECTION2A (Share_Driver, Password, Username, 1);
Return Ret;} catch (exception error) {throw new exception;}}
Public void Breakshare (string localpath) {int RET = WNETCANCONNECONNECTION2A (localpath, 1, 1);}