2012-11-24 3 views
3

IWshRuntimeLibrary를 사용하여 C#으로 바로 가기를 만듭니다. 바로 가기 파일 이름은 힌디어 "नमस्ते"입니다.유니 코드 문자로 바로 가기 만들기

나는 shortcut.Save()shortcutName = "नमस्ते.lnk"

WshShellClass wshShell = new WshShellClass(); 
IWshRuntimeLibrary.IWshShortcut shortcut; 

shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(destPath + "\\" + shortcutName); 

shortcut.TargetPath = sourcePath; 
shortcut.Save(); 

나는 다음과 같은 예외를 받고 있어요 곳, 바로 가기를 만들 다음 코드 내 싹둑를 사용하고 있습니다.

The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B) 

답변

4

당신은 디버거에 무엇이 잘못되었는지 알 수 있습니다. 디버거에서 "바로 가기"를 검사하고 힌디어 이름이 물음표로 바뀌 었는지 확인하십시오. 잘못된 파일 이름을 생성하고 예외를 트리거합니다.

문자열을 처리 할 수없는 고대 스크립팅 지원 라이브러리를 사용하고 있습니다. 좀 더 최신의 것을 사용해야 할 것입니다. 프로젝트 + 참조 추가, 찾아보기 탭에서 c : \ windows \ system32 \ shell32.dll을 선택하십시오. 쉘 관련 작업을 수행 할 수있는 몇 가지 인터페이스를 사용하여 프로젝트에 Shell32 네임 스페이스를 추가합니다. ShellLinkObject 인터페이스를 사용하면 .lnk 파일의 속성을 수정할 수 있습니다. 한 가지 트릭이 필요합니다. 새로운 .lnk 파일을 처음부터 만들 수는 없습니다. 빈 .lnk 파일을 작성하여이를 해결할 수 있습니다. 이것은 잘 작동 :

이 일이 일
string destPath = @"c:\temp"; 
    string shortcutName = @"नमस्ते.lnk"; 

    // Create empty .lnk file 
    string path = System.IO.Path.Combine(destPath, shortcutName); 
    System.IO.File.WriteAllBytes(path, new byte[0]); 
    // Create a ShellLinkObject that references the .lnk file 
    Shell32.Shell shl = new Shell32.Shell(); 
    Shell32.Folder dir = shl.NameSpace(destPath); 
    Shell32.FolderItem itm = dir.Items().Item(shortcutName); 
    Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink; 
    // Set the .lnk file properties 
    lnk.Path = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe"; 
    lnk.Description = "nobugz was here"; 
    lnk.Arguments = "sample.txt"; 
    lnk.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 
    lnk.Save(path); 
+0

아니라 파일 시스템에서를 Shell32.dll을 참조하는 하나 명의 변경은 "심판 추가 ..."대화 상자의 COM 탭으로 이동하여 "마이크로 소프트 쉘 컨트롤 및 자동화라는 구성 요소를 선택 " – Naresh

+0

아무런 차이가 없으므로 Browse 탭을 사용하면 파일을 더 쉽게 찾을 수 있습니다. –

+0

하지만 COM 구성 요소를 추가하면 장치 독립적 인 것으로 생각됩니다. 모든 사용자가 c : \를 주 디스크로 사용할 수있는 것은 아닙니다. – Naresh