简体   繁体   English

如何使用c#中的cmd将文件从任何目录复制到c盘

[英]how to copy a file from any directory to c drive using cmd in c#

i tried an image file to copy in c:(operating sys) drive,but it says error wid access denied,i have used as 我尝试了一个图像文件复制到c :(操作系统)驱动器,但它说错误wid访问被拒绝,我用过

string strCmdLine;
    strCmdLine = @" /c xcopy d:\123.png C:\windows\system32";
    Process.Start("CMD.exe", strCmdLine);

you probably dont have enough permissions.... 你可能没有足够的权限....

try adding credentials : 尝试添加凭据:

    Process p = new Process();
    process.StartInfo.UserName = "aaaa";  
    process.StartInfo.Password = "xxxxx";
...
...

also , verify that : 另外,验证:

read permissions for : d:\\123.png 读取权限: d:\\123.png

write permissions for : C:\\windows\\system32 写权限: C:\\windows\\system32

Access Denied may be caused by several reasons, such as user permissions or file being in use. 拒绝访问可能是由多种原因引起的,例如用户权限或正在使用的文件。 Since the command line seems to be OK, I suggest to check whether your application was run by a Windows user that has permission to write to C:\\windows\\system32. 由于命令行似乎没问题,我建议检查您的应用程序是否由有权写入C:\\ windows \\ system32的Windows用户运行。

you need to run CMD.exe as admin try following 您需要运行CMD.exe作为管理员尝试以下

        Process p = new Process();
        p.StartInfo.FileName = "cmd.exe";
        p.StartInfo.Verb = "runas";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardInput = true;
        p.Start();

        p.StandardInput.WriteLine(@"/c xcopy d:\123.png C:\windows\system32");

You can check This post which shows how to run program as admin. 您可以查看帖子,其中显示了如何以管理员身份运行程序。

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

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