1

管理者として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.

4

3 に答える 3

0

Web アプリをローカルで実行しているか、ネットワーク経由で実行しているかによって異なりますが、通常は C ドライブに書き込むために、ターゲット フォルダーに NETWORK SERVICE を追加できます。

于 2013-04-01T09:50:53.753 に答える
0

これをコードに追加します。

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

この助けを願っています。

于 2013-04-01T09:59:50.097 に答える