Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. File delete permission problem

File delete permission problem

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharphtmlhelpquestionlearning
14 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P primem0ver

    Did you read my post? I already specified that. Specifically the program saves an Excel file "as an html file in the user's document folder. This automatically generates the [excel_file_name]_files subfolder... The program ALSO auto-generates jpg images every time... and saves those images in this sub-folder." If that is too confusing, it is a subfolder of %USERPROFILE%\Documents created by Excel. This is BEFORE the application exports any excel files to html so the folder is not in use... and my application checks to make sure the folder exists before attempting any file operations; just in case the user has not ever used the program before.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #5

    I read your post. Your concept of the "user's document folder" could have no basis in reality. That's is why we use "enumerations" to insure we use something "familiar" to the OS. Got it?

    "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

    P 1 Reply Last reply
    0
    • D Dave Kreskowiak

      This doesn't make sense. Any code launched by the user runs AS THE USER. The user will have full access, including delete permissions, to anything under their profile, including the Documents folder. The code will be executing as the user as it will inherit the users seecurity token on launch. SO, if the user has permissions to delete files, the code will to. Code cannot grant itself more permissions than it already has. The user can't do that, so the code won't be able to do it either. What type of app is this? What account is the app running under? Does the user launch this app?

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      P Offline
      P Offline
      primem0ver
      wrote on last edited by
      #6

      It is an app run by the user that ls logged in. IT seems to be working now but it crashed previously. From my experience, applications have their own permission sets. Are you saying this is not the case? I have had several experiences that would suggest otherwise; the latest being that on Windows 10 a downloaded Excel document opened by the user in excel will allow itself to be read because I have overridden the default behavior. However, if the user launches my application to do the same thing, it will crash with a COM error that appears to be related to the fact that downloaded files are not allowed to be read under the current permissions. This is unique to Windows 10 as it does not happen under Windows 7. I had to import a non-COM Excel reader when I ported to Windows 10 in order to get it to read excel files without crashing (or without me personally opening the files myself in debug mode).

      D 1 Reply Last reply
      0
      • P primem0ver

        It is an app run by the user that ls logged in. IT seems to be working now but it crashed previously. From my experience, applications have their own permission sets. Are you saying this is not the case? I have had several experiences that would suggest otherwise; the latest being that on Windows 10 a downloaded Excel document opened by the user in excel will allow itself to be read because I have overridden the default behavior. However, if the user launches my application to do the same thing, it will crash with a COM error that appears to be related to the fact that downloaded files are not allowed to be read under the current permissions. This is unique to Windows 10 as it does not happen under Windows 7. I had to import a non-COM Excel reader when I ported to Windows 10 in order to get it to read excel files without crashing (or without me personally opening the files myself in debug mode).

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #7

        primem0ver wrote:

        From my experience, applications have their own permission sets. Are you saying this is not the case?

        Correct. Applications ALWAYS run as the user the launched them, inheriting the security token (permissions) of the user. There is no way to get around this. Applications also cannot grant themselves permissions over and above what they inherited from launch. That was be a massive security risk. Windows, and every other O/S with security built into it, simply does not allow that to happen. The sole exception of this is when running under Vista and above, an administrator user account can be split into two security contexts, the normal user version of the account and the administrator version. Normally, everything runs as the normal user account, unless admin permissions are required. That's when User Account Control comes in and asks if you really want to run something as an administrator, or if you explicitly launch the process "as administrator". You've got a different problem with your code. It's not permissions.

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        P 1 Reply Last reply
        0
        • L Lost User

          I read your post. Your concept of the "user's document folder" could have no basis in reality. That's is why we use "enumerations" to insure we use something "familiar" to the OS. Got it?

          "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

          P Offline
          P Offline
          primem0ver
          wrote on last edited by
          #8

          Regardless, the enumeration resolves to a location determined by the .NET implementation for the specific OS. I am using the enumeration by default so whatever that returns is what I am using. The user has the option to change this but it doesn't matter in context as user specific considerations would not be an issue in a custom folder unless those permissions are altered to something other than the default (which is beyond my control).

          L 1 Reply Last reply
          0
          • D Dave Kreskowiak

            primem0ver wrote:

            From my experience, applications have their own permission sets. Are you saying this is not the case?

            Correct. Applications ALWAYS run as the user the launched them, inheriting the security token (permissions) of the user. There is no way to get around this. Applications also cannot grant themselves permissions over and above what they inherited from launch. That was be a massive security risk. Windows, and every other O/S with security built into it, simply does not allow that to happen. The sole exception of this is when running under Vista and above, an administrator user account can be split into two security contexts, the normal user version of the account and the administrator version. Normally, everything runs as the normal user account, unless admin permissions are required. That's when User Account Control comes in and asks if you really want to run something as an administrator, or if you explicitly launch the process "as administrator". You've got a different problem with your code. It's not permissions.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            P Offline
            P Offline
            primem0ver
            wrote on last edited by
            #9

            Ok. I am following you. I realize that permissions inherited from the user make sense. However, having an application run with fewer permissions than the user is not a safety hazard in terms of security and my experience is that this can happen. Another example (which is incidentally timely, and appropriate for this thread) is that permissions are an issue with certain virtual system accounts on which older versions of this program run. (The creation and deleting of jpgs is a new, unreleased, feature). I have isolated the old issue to something in the way permissions are granted to newer versus older users. The following code causes the application to crash for newer users only. The folder being searched (directoryInfo) is the Downloads folder for the user:

            FileInfo[] fileInfos = directoryInfo.GetFiles("GeniusExport*.*", SearchOption.TopDirectoryOnly); // CAUSES CRASH ON VM

            For all users, the user profile directory is a mapped drive. Perhaps directoryInfo resolves to something non-existent for newer users and perhaps I should test that; however this is a Windows 10 environment. I know for a fact that the people I have worked with who have this problem have a Downloads folder that is being used.

            D 1 Reply Last reply
            0
            • P primem0ver

              Ok. I am following you. I realize that permissions inherited from the user make sense. However, having an application run with fewer permissions than the user is not a safety hazard in terms of security and my experience is that this can happen. Another example (which is incidentally timely, and appropriate for this thread) is that permissions are an issue with certain virtual system accounts on which older versions of this program run. (The creation and deleting of jpgs is a new, unreleased, feature). I have isolated the old issue to something in the way permissions are granted to newer versus older users. The following code causes the application to crash for newer users only. The folder being searched (directoryInfo) is the Downloads folder for the user:

              FileInfo[] fileInfos = directoryInfo.GetFiles("GeniusExport*.*", SearchOption.TopDirectoryOnly); // CAUSES CRASH ON VM

              For all users, the user profile directory is a mapped drive. Perhaps directoryInfo resolves to something non-existent for newer users and perhaps I should test that; however this is a Windows 10 environment. I know for a fact that the people I have worked with who have this problem have a Downloads folder that is being used.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #10

              This isn't a permissions problem in the normal sense. That little line of code works on every machine and VM I have, under every account I normally use. This is something unique to your environment. Perhaps a problem caused by antivirus or some other security software software. I'm working with large antivirus vendor right now on a problem that causes Excel to crash on first start after a certain app is installed, which is just a add-in for Excel. Disabling the antivirus doesn't fix the problem. Stopping every single process in the antivirus or uninstalling it completely fixes the problem.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              L P 2 Replies Last reply
              0
              • P primem0ver

                Regardless, the enumeration resolves to a location determined by the .NET implementation for the specific OS. I am using the enumeration by default so whatever that returns is what I am using. The user has the option to change this but it doesn't matter in context as user specific considerations would not be an issue in a custom folder unless those permissions are altered to something other than the default (which is beyond my control).

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #11

                I asked a simple question; that was all. If you think you provided all the "facts" needed to provide an "informed response", then we disagree. I don't know you from Adam; and if I assumed everyone always knew what they were talking about, I would be dead a couple of times over by now; or sued.

                "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                1 Reply Last reply
                0
                • D Dave Kreskowiak

                  This isn't a permissions problem in the normal sense. That little line of code works on every machine and VM I have, under every account I normally use. This is something unique to your environment. Perhaps a problem caused by antivirus or some other security software software. I'm working with large antivirus vendor right now on a problem that causes Excel to crash on first start after a certain app is installed, which is just a add-in for Excel. Disabling the antivirus doesn't fix the problem. Stopping every single process in the antivirus or uninstalling it completely fixes the problem.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                  Dave Kreskowiak

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #12

                  I have a "user files" implementation in C# / WPF that been running from XP through to W10, and EVERYTHING in between ... (including Windows 7 VM's; Hyper-V and VMBox) Fixed disk, memory card; USB stick. "Local" database files; created and deleted. Multi-threaded mirroring. Blah, blah. Automatically elevates for creating directories. (Uses "Special" folders enumerations). I agree; it's not "security".

                  "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                  1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    This isn't a permissions problem in the normal sense. That little line of code works on every machine and VM I have, under every account I normally use. This is something unique to your environment. Perhaps a problem caused by antivirus or some other security software software. I'm working with large antivirus vendor right now on a problem that causes Excel to crash on first start after a certain app is installed, which is just a add-in for Excel. Disabling the antivirus doesn't fix the problem. Stopping every single process in the antivirus or uninstalling it completely fixes the problem.

                    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                    Dave Kreskowiak

                    P Offline
                    P Offline
                    primem0ver
                    wrote on last edited by
                    #13

                    This seems to be the cause of my problem as well. I close the antivirus software and it works fine. Wow. How are you dealing with this?

                    D 1 Reply Last reply
                    0
                    • P primem0ver

                      This seems to be the cause of my problem as well. I close the antivirus software and it works fine. Wow. How are you dealing with this?

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #14

                      In your case, it's probably going to be as simple as adding an exception for your app in the antivirus policies, if that's supported. For me, it's a ticket open with the antivirus vendor for the last month and a metric shit ton of troubleshooting.

                      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                      Dave Kreskowiak

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups