2017-10-05 86 views
1

我想創建一個自定義Windows快捷方式並將其下載到asp.mvc中。 具體而言,我希望能夠以動態服務器作爲參數下載遠程桌面快捷方式。創建Windows快捷方式並在ASP.NET中下載它

我在互聯網上穿越了這個例子,但顯然不適用於web應用程序。

public ActionResult Download() 
    { 
      WshShell wsh = new WshShell(); 
      IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut("/shorcut.lnk") as IWshRuntimeLibrary.IWshShortcut; 
      shortcut.Arguments = ""; 
      shortcut.TargetPath = "c:\\app\\myftp.exe"; 
      // not sure about what this is fro 
      shortcut.WindowStyle = 1; 
      shortcut.Description = "my shortcut description"; 
      shortcut.WorkingDirectory = "c:\\app"; 
      //shortcut.IconLocation = "specify icon location"; 
      shortcut.Save(); 

     return File("/shorcut.lnk", "application/octet-stream", "shorcut.lnk"); 
    } 

我得到了一個普通的訪問被拒絕。還有另一種方法可以做到嗎?

+0

哪條線給你的拒絕訪問錯誤? –

回答

0

我把問題帶到了錯誤的方向,我不需要做mstsc.exe的快捷方式,但我需要創建我自己的rdp文件,其中包含非常簡單的文本作爲參數。

public ActionResult Download() 
     { 
      StringBuilder sb = new StringBuilder(); 
      string srv = "mysrv.myurl.com"; 
      sb.AppendFormat("full address:s:{0}", srv); 
      return File(Encoding.UTF8.GetBytes(sb.ToString()), 
      "text/plain", 
       string.Format("{0}.rdp", srv)); 
     } 

這是工作

相關問題