上传文件到program files\某些商业程序时路径被拒绝访问
我收到错误:
Access to the path 'C:\Program Files (x86)\MetaTrader FIX\experts\indicators\Awesome.ex4' is denied./n at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.Create(String path)
at Iron_loader.Program.Main(String[] args) in C:\Users\Damian\Documents\Visual Studio 2010\Projects\Iron loader\Iron loader\Program.cs:line 55
当我从 \bin\Debug 运行我的 exe 文件时。 我不知道这是为什么。在目标目录中没有这样的文件,所以我认为存在安全问题,因为当我以管理员身份从 VS 运行我的程序时,一切正常。
我正在尝试将文件上传到其他程序的文件夹(不是我的)。 我怎样才能复制该文件?
File.Create(newPath);
File.Copy(pathOfFileFromMyDebugDirectory, newPath);
I get an error :
Access to the path 'C:\Program Files (x86)\MetaTrader FIX\experts\indicators\Awesome.ex4' is denied./n at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.Create(String path)
at Iron_loader.Program.Main(String[] args) in C:\Users\Damian\Documents\Visual Studio 2010\Projects\Iron loader\Iron loader\Program.cs:line 55
when I run my exe file from \bin\Debug .
I don't know why is that. In destination directory there is no such file, so I think that there is a problem with security, ecause when I run my program from VS as admin everything goes ok.
I'm trying to upload files to folder of other program(not mine).
How can I copy that file?
File.Create(newPath);
File.Copy(pathOfFileFromMyDebugDirectory, newPath);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查文件夹的权限。用户没有修改/完全控制权限。
选择文件夹上的属性,然后选择“安全”选项卡并检查当前用户或您的应用程序的用户的权限。正在运行。
Check permissions on the folder. The user doesn't have modify / Full Control permissions.
Select property on the folder then select Security tab and check permissions for the current user or the user that your app. is running as.
如果是WindowsXP及以下操作系统,epoxy将无法读写C:\ProgramFilesx86,因为uac。
您必须以管理员权限启动您的应用程序。
问候。
if the operating system and following WindowsXP, epoxy will not read and write in C: \ ProgramFilesx86, because the uac.
You must start your application with administrator privileges.
Regards.
...参见下面的编辑
我相信部分问题是“进程”尚未释放文件句柄。试试这个:
一旦您点击 using 块中的右大括号,就会调用基本流
Dispose()
方法,并且所有资源(包括进程的文件句柄)都应该被释放。编辑
您在“File.Create”调用中遇到异常吗?我误读了你给出的错误。如果您在 Create() 方法中遇到异常,则需要确保您有权利写入路径。
我相信,当您纠正权限问题时,您可能会收到一个异常,即该句柄正在被另一个进程使用。如果是这样,请使用我上面的建议来修复。
...see Edit below
I believe that part of the problem is that the 'process' has not yet released the file handle. Try this:
As soon as you hit the closing brace in the using block, the base stream
Dispose()
method is called and all resources - including the process' file handle - should be released.Edit
Are you getting the exception at the 'File.Create' call? I misread the error you gave. If you are getting the exception at the Create() method, then you need to make sure you have the right to write to the path.
I believe, that when you rectify the rights issue, you may get an exception that the handle is in use by another process. If so, use my suggestion above to fix.