The shared folder in the LAN can be accessed only by using the user name and password. How can I obtain the folder access permission through a program?
The "net use" command in the doscommand is mainly used here.
Public Static Void Getaccesscontrol ( String Path, String User, String PWD) {PROCESS p = New Process (); p. startinfo. filename = System. environment. getenvironmentvariable (" Comspec " ); P. startinfo. useshellexecute = False ; P. startinfo. redirectstandardinput = True ; P. startinfo. redirectstandardoutput = True ; P. startinfo. createnowindow = True ; P. Start (); p. standardinput. writeline ( @" Net use {0}/del " , PATH );// You must delete it first. Otherwise, an error is returned.P. standardinput. writeline ( @" Net use {0} "" {1} "/User: {2} " , Path, PWD, user); p. standardinput. writeline ( " Exit " );// If this waitforexit clause is not added, it will get stuck.P. waitforexit (); p. Close ();}
If you have any better methods, please feel free to advise.