2017-02-23 63 views
0

我想建立一個快捷方式,並保存到桌面的公共文件夾,但與此代碼拋出UnauthorizedAccessException:UnauthorizedAccessException公共桌面文件夾用C#

 WshShell wsh = new WshShell(); 
     IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
      Environment.GetEnvironmentVariable("ALLUSERSDESKTOP") + "\\App.lnk") as IWshRuntimeLibrary.IWshShortcut; 
     shortcut.Arguments = " some arguments"; 
     shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\App\\to\\link\\app.exe"; 
     shortcut.Description = "Description"; 
     shortcut.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\App\\to\\link\\"; 
     shortcut.Save(); 

這個代碼在Windows服務運行,有什麼建議? ?

幫助PLZ = S

+0

用戶什麼是Windows服務運行? –

+0

管理員用戶權限,W10 ... – IvanVazquez

回答

0

過了一會兒......我做到了!

所有你需要做的就是添加一個應用程序清單文件的項目,並加入這一行:

<requestedExecutionLevel level="highestAvailable" uiAccess="false" /> 

和多數民衆贊成,我希望這可以usseful的人...

相關問題