以管理员身份复制到C Drive(Root)

时间:2013-04-01 09:45:25

标签: asp.net

我想以管理员身份复制C根目录中的文件,它适用于某些路径。我使用的用户具有管理员权限,但我仍然无法复制。

我的代码是:

string strCmdText = string.Empty;
strCmdText = "copy /Y " + "\"" + fullpath + "\"" + " " + "\"" + _name.FullPath + "\\" + subject + ".msg" + "\"";
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Verb = "runas";
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
startInfo.UseShellExecute = false;
startInfo.Arguments = strCmdText;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.StartInfo = startInfo;
process.Start();
StreamWriter sw = process.StandardInput;
sw.WriteLine(strCmdText);
sw.Close();
process.WaitForExit();
string output = process.StandardOutput.ReadToEnd();
process.Dispose();
process.Close();

我收到以下错误: You don't have appropriate permission to perform this operation.

3 个答案:

答案 0 :(得分:0)

根据您在本地或通过网络运行Web应用程序,但通常要写入C盘,您可以将NETWORK SERVICE添加到目标文件夹。

答案 1 :(得分:0)

将此添加到您的代码中:

startInfo.UserName = "Administrator";
startInfo.Password = "password";

希望这个帮助。

答案 2 :(得分:0)

取自评论。这看起来像UAC。尝试关闭UAC,如果有效,那么你知道下一步该去哪里!