简体   繁体   English

C# Windows-Form-Application Process.Start() 给出“访问被拒绝”错误

[英]C# Windows-Form-Application Process.Start() Gives "Access is denied" Error

I work on C# Windows-Form-Application (WinForms) and used the following code:我在 C# Windows-Form-Application (WinForms) 上工作并使用以下代码:

System.Diagnostics.Process.Start("x");

where 'x' is the path to the folder should be open (a local folder not in C:\ ).其中“x”是应该打开的文件夹的路径(不在 C:\ 中的本地文件夹)。

The Problem is that when running the program it gives me "Access is denied" Error !问题是在运行程序时它给了我“访问被拒绝”错误!

I Searched on Google but i did not find how to solve this problem.我在谷歌上搜索,但我没有找到解决这个问题的方法。

Note: This Code works on Console Apps & Windows-Form (Dot Net framework).注意:此代码适用于控制台应用程序和 Windows 窗体(Dot Net 框架)。

This seems like a standard permissions issue.这似乎是一个标准权限问题。 The account running the application does not have the correct permissions to access the folder.运行应用程序的帐户没有访问该文件夹的正确权限。 If you are debugging from Visual Studio, then try running VS as an administrator.如果您从 Visual Studio 调试,请尝试以管理员身份运行 VS。 If you are running an installation of the app then run the app itself as an administrator.如果您正在运行应用程序的安装,则以管理员身份运行应用程序本身。

Update:更新:

Looks like simply calling Process.Start with the folder path will not work in .net core.看起来像在 .net 内核中使用文件夹路径简单地调用Process.Start将不起作用。 In .net core you need to specify the application as well as the folder path:在 .net 内核中,您需要指定应用程序以及文件夹路径:

System.Diagnostics.Process.Start("explorer.exe", "[FolderPath]");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM