Reputation: 23
i tried an image file to copy in c:(operating sys) drive,but it says error wid access denied,i have used as
string strCmdLine;
strCmdLine = @" /c xcopy d:\123.png C:\windows\system32";
Process.Start("CMD.exe", strCmdLine);
Upvotes: 0
Views: 1362
Reputation: 2601
you need to run CMD.exe as admin try following
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.
Upvotes: 0
Reputation: 42153
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.
Upvotes: 1
Reputation: 148684
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
write permissions for : C:\windows\system32
Upvotes: 1