简体   繁体   English

访问路径'c:\\ ApplicationFolder'被拒绝

[英]Access to the path 'c:\ApplicationFolder' is denied

I am getting a strange error on a remote windows clients (WinForm application using C# 2.0) 我在远程Windows客户端上遇到一个奇怪的错误(使用C#2.0的WinForm应用程序)

Error Message: Access to the path 'c:\\ApplicationFolder' is denied. 错误消息:拒绝访问路径'c:\\ ApplicationFolder'。

Stack Trace: 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) 堆栈跟踪:在System.IO .__ Error.WinIOError(Int32 errorCode,String maybeFullPath)在System.IO.FileStream.Init(字符串路径,FileMode模式,FileAccess访问,Int32权限,布尔useRights,FileShare共享,Int32 bufferSize,FileOptions选项) ,SECURITY_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy)

Let me say I know I should not put the application folder directly off the c:\\ folder. 让我说我知道我不应该将应用程序文件夹直接放在c:\\文件夹下。 This an old application that I have no control over. 这是一个我无法控制的旧应用程序。

It likely comes down to the reason that you shouldn't put the application folder there: standard users don't have write access by default. 这可能归结为,你不应该把应用程序文件夹存在的原因 :标准用户不具有默认的写入权限。 Since most people run Windows as administrator it's not often a problem, but if you try to install on a corporate environment that recently updated security policies you would suddenly have a serious problem. 由于大多数人以管理员身份运行Windows,因此通常不会出现问题,但如果您尝试在最近更新安全策略的企业环境中安装,则会突然出现严重问题。

Have you checked the permissions on the folder? 你检查过该文件夹的权限了吗?

您可能正在尝试在只读文件上获得写访问权限。

A question, and a suggestion. 一个问题和一个建议。

Does the file path reported in the message exactly match the name of the folder - letter casing, spaces, underscores, accents, everything? 消息中报告的文件路径是否与文件夹的名称完全匹配 - 字母大小写,空格,下划线,重音符号,所有内容?

Why? 为什么? I've seen oddball cases where this caused a problem. 我见过古怪的情况,这引起了一个问题。

Suggestion: Use ProcessMonitor (from SysInternals, now part of Microsoft) to watch access to the folder, you'll see more details about the error - especially useful if the error reporting you're seeing isn't accurate. 建议:使用ProcessMonitor (来自SysInternals,现在是Microsoft的一部分)来监视对该文件夹的访问,您将看到有关该错误的更多详细信息 - 如果您看到的错误报告不准确,则尤其有用。

Create and Embed Manifest File in Your Application to get the Administrative Rights for your application 在应用程序中创建和嵌入清单文件以获取应用程序的管理权限

Executable: IsUserAdmin.exe 
Manifest:IsUserAdmin.exe.manifest
Sample application manifest file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="IsUserAdmin"
     type="win32"/> 
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

Here requireAdministrator says your application requires admin rights This will cause a confirmation Dialogue when user starts your app. 这里requireAdministrator说您的应用程序需要管理员权限当用户启动您的应用程序时,这将导致确认对话。

Does the app at least load the "application folder" from a config file / the registry / a database table? 应用程序是否至少从配置文件/注册表/数据库表中加载“应用程序文件夹”? If so, what happens when you change that value to something in the My Documents folder? 如果是这样,当您将该值更改为“我的文档”文件夹中的某些内容时会发生什么?

I saw you added the user is an admin and has full admin rights so I have to ask the obvious -- does the folder exist where the code thinks it should? 我看到你添加了用户是一个管理员,并拥有完全的管理员权限,所以我不得不问明显的 - 文件夹是否存在代码认为应该的位置?

Agree with process monitor being helpful, saved several hours of my day. 同意过程监控有用,节省了我一天中的几个小时。 Had the args to Path.Combine flipped so I ended up trying to write to the directory in lieu of the file. 如果将Path.Combine的args翻转,那么我最终试图写入目录而不是文件。 no hints in debug, process mon showed right up. 在调试中没有提示,进程mon显示正确。

System.IO.FileStream.Init sounds like you're opening a file, not a folder. System.IO.FileStream.Init听起来像是在打开文件,而不是文件夹。 What is the file? 什么是文件?

Are you sure the file exists? 你确定文件存在吗? That it is not opened by another app? 它不是由另一个应用程序打开的? Are you trying to write to the file? 你想写信给文件吗? Is it locked or read-only? 是锁定还是只读?

We need to see the code that's opening the file. 我们需要查看打开文件的代码。

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

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