2009-11-27 12 views
5

네트워크 드라이브에 파일을 쓰려고하면 연결이 끊어지면서 오류가 발생합니다.연결이 끊긴 네트워크 드라이브 다시 연결

탐색기에서 드라이브를 더블 클릭하면 네트워크 드라이브가 다시 연결됩니다.

System.Io.Driveinfo.IsReady를 사용하면 드라이브가 준비되었는지 확인할 수 있지만 코드로 어떻게 다시 연결할 수 있습니까?

답변

5

code은 드라이브를 매핑하고 런타임에 동적으로 매핑 해제하는 방법을 보여줍니다. 이것은 CodeGuru에 있습니다.

+1

이 코드는 Windows Vista에서 더 이상 작동하지 않습니다. – AndresRohrAtlasInformatik

0

@AndresRohrAtlasInformatik이 지적했듯이 수용된 솔루션은 Windows Vista 이상에서는 작동하지 않습니다.

내 솔루션은 탐색기를 숨겨진 창으로 시작하고 네트워크 드라이브로 이동하여 탐색기를 닫는 것입니다. 후자는 탐색기가 여러 창에 대해 매우 특별한 동작을하기 때문에 조금 더 어렵습니다 (here 참조).

ProcessStartInfo info = new ProcessStartInfo("explorer.exe", myDriveLetter); 
info.WindowStyle = ProcessWindowStyle.Hidden; 
Process process = new Process(); 
process.StartInfo = info; 
process.Start(); 
Thread.Sleep(1000); 
//bool res = process.CloseMainWindow(); // doesn't work for explorer !! 
//process.Close(); 
//process.WaitForExit(5000); 

// https://stackoverflow.com/a/47574704/2925238 
ShellWindows _shellWindows = new SHDocVw.ShellWindows(); 
string processType; 

foreach (InternetExplorer ie in _shellWindows) 
{ 
    //this parses the name of the process 
    processType = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); 

    //this could also be used for IE windows with processType of "iexplore" 
    if (processType.Equals("explorer") && ie.LocationURL.Contains(myDriveLetter)) 
    { 
     ie.Quit(); 
    } 
} 
관련 문제