.NET 1.0 일 전 MS Windows에서 바로 가기의 대상을 반환하는 메서드를 작성했습니다. 그것은 개체 모델과 짐승이 COM 인터페이스를 통해 강제 호스팅 Windows 스크립트에 상호 운용성을 사용을 통해 이런 짓을 :COM을 사용하지 않고 C#에서 프로그래밍 방식으로 Windows 파일 시스템 바로 가기를 따르는 방법이 있습니까?
private FileInfo GetFileFromShortcut(FileInfo shortcut)
{
FileInfo targetFile = null;
try
{
IWshRuntimeLibrary.WshShell wShell = new IWshRuntimeLibrary.WshShellClass();
IWshRuntimeLibrary.WshShortcut wShortcut = (IWshRuntimeLibrary.WshShortcut)wShell.CreateShortcut(shortcut.FullName);
// if the file wasn't a shortcut then the TargetPath comes back empty
string targetName = wShortcut.TargetPath;
if (targetName.Length > 0)
{
targetFile = new FileInfo(targetName);
}
}
catch (Exception)
{ // will return a null targetFile if anything goes wrong
}
return targetFile;
}
이 여전히 버그에게 나를, 나는하지만, 더 우아한 뭔가이 찾고 교체 된 경우에만 교체 작업은 실제로 최소한 효과적입니다. 난 아직도 C# 방식으로 바로 가기의 대상을 찾는 방법을 찾을 수 없습니다. 그 중 하나가 있습니까, 아니면 아직도이 유형의 일을하는 가장 좋은 방법입니까?
큰 질문입니다. COM interop없이이 작업을 수행하는 방법에 대해 생각하지 않았습니다. – Sung
불행하게도 이것을 달성하기 위해 관리되지 않는 코드를 통해 셸을 사용하는 것을 피할 수 없었습니다. – RobS