C # user name password access LAN share

Source: Internet
Author: User

        #region Ping returns True to indicate that a successful public bool Ping (string remotehost) {bool Flag = false can be connected;            Process proc = new process (); try {Proc.                Startinfo.filename = "cmd.exe"; Proc.                Startinfo.useshellexecute = false; Proc.                Startinfo.redirectstandardinput = true; Proc.                Startinfo.redirectstandardoutput = true; Proc.                Startinfo.redirectstandarderror = true; Proc.                Startinfo.createnowindow = true; Proc.                Start ();                String dosline = @ "Ping-n 1" + remotehost; Proc.                Standardinput.writeline (Dosline); Proc.                Standardinput.writeline ("Exit"); while (!proc. hasexited) {Proc.                WaitForExit (500); } string pingresult = Proc. Standardoutput.readtoend ().                Replace ("Request timed out", "unable to access the target host"); if (Pingresult.indexof ("Unreachable target host") ==-1) {Flag = true; } proc.            Standardoutput.close (); } catch (Exception ex) {} finally {Proc.                Close (); Proc.            Dispose ();        } return Flag; } #endregion

        #region Connect LAN Returns True to indicate that a successful public bool connect can be connected (string remotehost, String userName, String passwo            RD) {bool Flag = false;            Process proc = new process (); try {Proc.                Startinfo.filename = "cmd.exe"; Proc.                Startinfo.useshellexecute = false; Proc.                Startinfo.redirectstandardinput = true; Proc.                Startinfo.redirectstandardoutput = true; Proc.                Startinfo.redirectstandarderror = true; Proc.                Startinfo.createnowindow = true; Proc.                Start (); Proc.  Standardinput.writeline ("net use */del/y"); Disconnect all connections in string dosline = @ "net use \ \" + RemoteHost + "" + PassWord + "+"/user: "+ userName +" >                NUL "; Proc.                Standardinput.writeline (Dosline); Proc.                Standardinput.writeline ("Exit"); while (!proc. hasexited) {Proc. WaitForExit (1000); } string errormsg = Proc.                Standarderror.readtoend (); Proc.                Standarderror.close ();                if (String.IsNullOrEmpty (errormsg)) {Flag = true; }} catch (Exception ex) {} finally {Proc.                Close (); Proc.            Dispose ();        } return Flag; } #endregion

  

C # user name password access LAN share

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.