简体   繁体   English

写入appdata文件夹-权限问题?

[英]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. 在启动时,应用程序将检查资源是否存在于appdata文件夹中,如果不存在,则在加载模板文件之前将模板文件从嵌入式资源复制到appdata文件夹中,然后使用appdata文件夹中的模板文件作为工作副本。

I have a helper class which amongst other things returns the appdata and resources subfolder as follows: 我有一个帮助器类,它除其他外还返回appdata和resources子文件夹,如下所示:

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: 因此,我的代码调用GetResourcesFolder方法,该方法返回路径(如果需要,可以在进程中创建文件夹),以检查文件是否存在以及是否不尝试使用以下方式写入文件:

        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. 但是,一些异地同事抱怨说,它们“崩溃”在他们的机器上(每种情况都是XP机器),但从他们那里回来的有用信息却不多,他们正在努力从他们那里获得更多信息。 I have XP machines in the office that it has worked on without problems. 我在办公室工作的XP机器没有问题。

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. 在挖掘出一些之前被“存档”的旧的开发机器之后,我已经设法在两台xp(sp2)机器上发生了崩溃。 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. 但是,一旦应用程序成功运行后,应用程序不再崩溃,即使我从appdata文件夹中删除了它创建的文件/文件夹,即使我没有提升权限,它也将在后续执行中成功创建。

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. 一个行动方案是创建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/ http://www.microsoft.com/windows/virtual-pc/

https://www.virtualbox.org/ 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. 与相关问题本身一样,我不知道比在虚拟机上安装VS以进行测试更好的方法。

+1 to Erik's VM solutions for reporducing the issue. 为Erik的VM解决方案提供+1,以便重新解决问题。

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. 为了追踪权限问题,请考虑使用ProcMon( http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx ) - 将显示您想要的所有内容(而不是:))关于文件/注册访问权限处理。 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. 我建议首先在机器上多次尝试它,你可以在程序中正常工作,为你的过程进行过滤设置,并了解应该发生什么。

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

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