2017-02-23 95 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的人...

相关问题