簡體   English   中英

使用C#的公用桌面文件夾上的UnauthorizedAccessException

[英]UnauthorizedAccessException on Public Desktop Folder with C#

我想創建一個快捷方式並保存到Desktop Public文件夾中,但是使用以下代碼拋出UnauthorizedAccessException:

        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 Services上運行,有什么建議嗎?

幫助Plz = S

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

您需要做的就是將App Manifest文件添加到項目中,並添加以下行:

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

僅此而已,我希望這可以對某人有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM