2012-10-05 2 views
0

내가 파일을 복사하려면이 코드를 사용하지만 지름길을 할 수없는 특별한 folder.I에 다른 응용 프로그램의 바로 가기를 복사 할 수 있습니다 C#을 가진 윈도우의 양식 응용 프로그램을 만들려고 노력하고있어 ...C#에서 다른 앱의 앱에 대한 바로 가기를 만드는 방법은 무엇입니까?

system.io.file.copy("what","where"); 

I 이 사용하지만 작동하지 않습니다.

 System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(".\\calc.exe"); 
     string destination = @"C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\Startup"; 
     System.IO.FileInfo[] files = dir.GetFiles("*.exe"); 

     foreach (var shorcut in files) 
     { 
      System.IO.File.Move(shorcut.FullName, destination); 
     } 

가장 쉬운 방법은 무엇입니까?

답변

0

다음 코드는 당신이 그것을 확인하는 쉬운 방법을하지 마십시오 LNK 파일

그것은 많은 이해가되지 않습니다를 읽을 수 있습니다. 나는 최선의 접근법은 .lnk 파일을 읽어야하는 방식으로 읽는 것이라고 생각한다. COM을 사용하면 ShellLinkObject 클래스가 IShellLink 인터페이스를 구현합니다. Project + 참조 추가, 찾아보기 탭을 시작하고 c : \ windows \ system32 \ shell32.dll로 이동하십시오. 이것은 interop 라이브러리를 생성합니다. 이 같은 코드를 작성합니다 :

public static string GetLnkTarget(string lnkPath) { 
    var shl = new Shell32.Shell();   // Move this to class scope 
    lnkPath = System.IO.Path.GetFullPath(lnkPath); 
    var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(lnkPath)); 
    var itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath)); 
    var lnk = (Shell32.ShellLinkObject)itm.GetLink; 
    return lnk.Target.Path; 
} 
다음

당신은 단순히 다음 코드

First include a reference to C:\Windows\System32\wshom.ocx 

Second, include the following using statement :- 

using IWshRuntimeLibrary; 

Third, Here is the code :- 

// This creates a Folder Shortcut 
IWshShell wsh = new WshShellClass(); 
IWshShortcut shortcut = (IWshShortcut) wsh.CreateShortcut (shortcutpathfilename); 
shortcut.TargetPath = targetdir; 
shortcut.Save(); 
shortcutpathfilename is a path & filename of the .lnk file. 
targetdir is the directory the link points to. 
를 사용하여 자신의 폴더에 저장
관련 문제