C#将文件复制到system32访问被拒绝 [英] C# copy file to system32 access denied

查看:729
本文介绍了C#将文件复制到system32访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
将文件复制到system32



代码:

hi copy file to system32

code:

private void button1_Click(object sender, EventArgs e)
        {
            string path64=null, path32 = null;
            if (Environment.Is64BitOperatingSystem)
            {
                path64 = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "SysWOW64\\");
                path32 = Environment.GetFolderPath(Environment.SpecialFolder.System)+"\\";
                MessageBox.Show(path64);
            }
            else
            {
                path32 = Environment.GetFolderPath(Environment.SpecialFolder.System);
                MessageBox.Show(path32);
            }

            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (path64 != null)
                {
                    System.IO.File.Copy(ofd.FileName, @path64 + ofd.SafeFileName);
                }
                System.IO.File.Copy(ofd.FileName, @path32 + ofd.SafeFileName);

            }
        }





错误:



error:

Access to the path is denied.





请帮帮我。



我尝试了什么:





please help me.

What I have tried:

hi
copy file to system32




please help me.

推荐答案

这很简单。 ..用户被禁止将文件复制到系统文件夹。



你可以通过在管理员模式下运行你的程序来解决它,但你不应该。



想想System32是什么(名称中的线索)以及为什么用户访问可能只读
It's quite simple. ..users are prevented from copying files to system folders.

You can get around it by running your program in Administrator mode, but you shouldn't.

Think about what System32 is (clue is in the name) and why user access might be read only


这篇关于C#将文件复制到system32访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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