简体   繁体   中英

Writing to appdata folder - permission issue?

I've had a scout around some answers to similar questions but they haven't really helped me much.

I have an app, into which I've embedded some resources. At launch the app checks to see if the resources exist in the appdata folder and if not copies the template files from the embedded resources to the appdata folder before loading them and then using the ones in the appdata folder as the working copies.

I have a helper class which amongst other things returns the appdata and resources subfolder as follows:

class Folders
{
    static public String GetUserFolder()
    {
        return Application.LocalUserAppDataPath;
    }

    static public String GetResourcesFolder()
    {
        // If the resources folder does not exist then create it
        String userFolder = GetUserFolder();
        String resourcesFolder = userFolder + "\\Resources";

        if (!Directory.Exists(resourcesFolder))
        {
            Directory.CreateDirectory(resourcesFolder);
        }
        return resourcesFolder;
    }

    ...

So my code calls the GetResourcesFolder method which returns the path (creating the folder in the process if it needs to) checks to see if the file exists and if it doesn't tries to write to it using something like:

        String filename = Helpers.IO.Folders.GetResourcesFolder() + "\\data.dat";
        FileStream outFile = System.IO.File.OpenWrite(filename);

So I've set the scene and this code is working on all the machines I had in the development office. However a couple of off site colleagues have complained it "crashes" on their machines - in each case an XP machine - but otherwise not a lot of useful information coming back from them - working on trying to get something more informative from them. I have XP machines in the office that it has worked on without problems.

After digging out some really old dev machines that were "archived" a while ago, I've managed to have a crash on two xp (sp2) machines also. On both occasions the crash seems to be related to write permissions and running the app using "Run As..." has resolved the problem and it executes correctly. However once the app has been successfully run once the app no longer crashes, even if I delete the files/folders it created from the appdata folder it will still create the successfully on subsequent executions even if I don't elevate permissions.

The problem I have is that I can now no longer repeat the crash on any dev machines available to me and I don't know how to go about putting the machine back into the state where I can.

Anybody got any ideas on what might be causing the problem, or how I may be able to return the machines to a "virgin" state to be able repeat the crash and help me track it down.

One course of action is to create a Virtual Machine of XP. You can save the state of the machine before install for testing. After your install just revert back to the previous state to test again. There are a few Vendors with free Virtual Machines:

http://www.microsoft.com/windows/virtual-pc/

https://www.virtualbox.org/

As too the related problem itself, I don't know a better way than to install VS on a virtual machine for testing purposes.

+1 to Erik's VM solutions for reporducing the issue.

For tracking down permissions issues consider using ProcMon ( http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx ) - will show enverything you ever wanted (and not :) ) about file/regisstry access made by a process. I'd recommend trying it several times first on machine where you program works fine to get filtering setup for your process and get a sense of what should be happening.

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