2016-10-19 19 views
0

我試圖創建使用IWshShortcut和WshShell的快捷方式。我的exe文件 - 爲此我創建快捷方式在文件名中有兩個點。 下面是我在做什麼:IWshShortcut目標路徑在目標文件名中不佔用兩個點

 string link = Path.Combine(TargetPath, Path.GetFileName(FileName) ?? FileName); 
      link = Path.ChangeExtension(link, string.Concat(Path.GetExtension(link), ShortcutExtensionString)); 

      var shell = new WshShell(); 
      var shortcut = shell.CreateShortcut(link) as IWshShortcut; 

shortcut.Description = Description; 
        shortcut.Arguments = string.Join(" ", Parameters); 
        shortcut.TargetPath = Path.Combine(WorkingDirectory, "CompanyName.ApplicationName.exe"); 
        shortcut.WorkingDirectory = string.IsNullOrWhiteSpace(WorkingDirectory) 
         ? TargetPath 
         : WorkingDirectory; 
        //save the shortcut. 
        shortcut.Save(); 

這樣,代碼得到執行良好,但在桌面快捷方式的目標路徑來截斷這樣的exe的名字:「E:\ OSO \軟件\ bin \ CompanyName.exe「 enter image description here

整個事情發生從筆記本電腦創建遠程服務器的快捷方式。我使用WNetAddConnection2連接到登錄用戶的服務器的桌面目錄(爲admin用戶提供用戶名和密碼)。

它似乎爲本地筆記本電腦工作正常,但。 我該如何解決這個問題?

回答

0

嘗試增加如下的目標路徑,

shortcut.TargetPath = WorkingDirectory + @"\CompanyName.ApplicationName.exe"; 
+0

不,沒有運氣。我忘記提到這個問題只在遠程創建的情況下(相應地更新我的問題)。 (還是)感謝你的建議。 – nilanjan

相關問題