如何确定安全的程序文件 [英] How do i determine program files the safe way

查看:61
本文介绍了如何确定安全的程序文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要一点帮助.我需要确定程序文件的文件夹中是否存在文件.如果该文件存在,则我的程序将其删除,然后将更新后的文件复制到该文件夹​​中.

我在测试时使用的是硬编码路径,现在我需要一些帮助来确定32位和64位的路径.

我是通过四处搜寻而发现此论坛的:

Hey guys,

I need a little bit of help. I need to determine if a file exists in a folder in program files. If the file exists my program deletes it and then copys over the updated file to the folder.

I was using hardcoded paths when testing it and now i need some help in determining the path for 32 bit and 64 bit.

i found this forumla from googling around:

static string ProgramFilesx86()
    {
        if( 8 == IntPtr.Size
            || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
        {
            return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
        }

        return Environment.GetEnvironmentVariable("ProgramFiles");
    }




我希望我能从中得到一些诚实的反馈,说明它的可靠性如何?据说这适用于32位64位和32位运行64位.


如果可以的话,请您解释如何使用该公式?

我实际上有一些文件将被复制,如果每次使用它都需要花费很长时间时,我都必须使用上述文件来确定路径.他们安全快捷吗?

谢谢.




I was hoping i can get some honest feedback on how reliable this is? This supposedly works for 32 bit 64 bit and 32bit running 64 bit.


And if it is reliable can you please explain how to use the formula?

I actually have a fair few files that will be copied over and if i have to use the above to determine the path everytime its going to take a long time. Is their a safe and quicker way?

Thanks.

推荐答案

[ ^ ]是您应该使用的
this[^] is what you should be using


这篇关于如何确定安全的程序文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆