简体   繁体   中英

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)

Error Message: Access to the path 'c:\\ApplicationFolder' is denied.

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)

Let me say I know I should not put the application folder directly off the c:\\ folder. 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.

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.

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.

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. no hints in debug, process mon showed right up.

System.IO.FileStream.Init sounds like you're opening a file, not a folder. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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