C # unblock file lock

Source: Internet
Author: User

 Public Static voidStreamsfile (stringFI) {                Try                {                    varp =NewProcess {startinfo={FileName= Environment.currentdirectory +"\\streams64.exe", UseShellExecute=false, Arguments="- d \ ""+fi+"\""                        }                    }; //Execution ParametersP.startinfo.useshellexecute =false;////Do not use system shell to start processP.startinfo.createnowindow =true;//do not show DOS program windowP.startinfo.redirectstandardinput =true; P.startinfo.redirectstandardoutput=true; P.startinfo.redirectstandarderror=true;//writes the external program error output to the StandardError streamP.errordatareceived + =NewDatareceivedeventhandler (p_errordatareceived); P.outputdatareceived+=NewDatareceivedeventhandler (p_outputdatareceived); P.startinfo.useshellexecute=false;                    P.start (); P.startinfo.windowstyle=Processwindowstyle.hidden; P.beginerrorreadline ();//start Asynchronous Readp.WaitForExit ();//blocking wait process endP.close ();//Close ProcessP.dispose ();//Freeing Resources                }                Catch(Exception e) {Console.WriteLine (e.tostring ()); }            }             Public Static voidP_errordatareceived (Objectsender, Datareceivedeventargs e)            {Console.WriteLine (e.data); }             Public Static voidP_outputdatareceived (Objectsender, Datareceivedeventargs e)            {Console.WriteLine (e.data); }

Just came across this problem, to use a Microsoft tool, can be in C # code through the process, the command line execution of this tool, you can unlock.
Specific look:

Using Streams

Usage:streams [-S] [-d] <file or directory>
-srecurse subdirectories.
-ddelete streams.
Streams takes wildcards e.g. ' Streams *.txt '.

Https://technet.microsoft.com/en-us/Sysinternals/bb897440.aspx

Https://download.sysinternals.com/files/Streams.zip

C # unblock file lock

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.