[英]ACCESS_DENIED in UWP app using ShellExecute
I am converting a C# WinForm app to UWP.我正在将 C# WinForm 应用程序转换为 UWP。
The old app is using pinvoke ShellExecute
API in order to open some files.旧应用程序使用 pinvoke ShellExecute
API 来打开一些文件。 I am trying to copy the same code to the new app, but get an exception.我正在尝试将相同的代码复制到新应用程序,但出现异常。
Here is my code:这是我的代码:
public static readonly int SHELL_EXECUTE_ERROR_CODE_LIMIT = 32;
[DllImport("shell32.dll")]
static extern IntPtr ShellExecute(
IntPtr hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
/*ShowCommands*/int nShowCmd);
private void btnPinvoke_Click(object sender, RoutedEventArgs e)
{
int ret = 0;
IntPtr retPtr = ShellExecute(IntPtr.Zero, "open", @"C:\path\to\file\dummy.pdf", "", "", /*ShowCommands.SW_SHOWNOACTIVATE*/4);
ret = retPtr.ToInt32();
if (ret <= SHELL_EXECUTE_ERROR_CODE_LIMIT) //Failure
{
lblResult.Text = "Error " + ret;
}
}
The error code which is returning is 5.返回的错误代码是 5。
ERROR_ACCESS_DENIED ERROR_ACCESS_DENIED
5 (0x5) 5 (0x5)
Can you help me understand why am I getting ACCESS_DENIED exception?你能帮我理解为什么我会收到 ACCESS_DENIED 异常吗?
It happens also when running Visual Studio as Administrator.以管理员身份运行 Visual Studio 时也会发生这种情况。
Maybe you can try也许你可以试试
Diagnostics.Process.Start(@"C:\path\to\file\dummy.pdf");
I used this many times in my applications and it works我在我的应用程序中多次使用它并且它有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.