私は、c#サービスを使用して、ユーザーから特定のフォルダをブロックしたいと考えています。つまり、サービスがブロックされているにもかかわらずサービスを開始すると、最終的な結果はブロックされたフォルダになります。私はコードを書いた。回答はですか?あなたはCACLSプロセスの標準入力をリダイレクトしている。このc#windowsサービスでCACLSを使用する方法
string Pathname = folder;
EventLog.WriteEntry(Pathname);
string Username = @"BUILTIN\Users";
string UserRights = "N";
if (Pathname == null || Pathname == "")
{
EventLog.WriteEntry("No File");
}
string CommandLine = '"' + System.IO.Path.GetFullPath(Pathname) + '"' + " /C ";
CommandLine += @" /T ";
CommandLine += @" /P " + Username + ":" + UserRights;
Process p = new Process();
p.StartInfo.FileName = "cacls.exe";
p.StartInfo.Arguments = CommandLine;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
p.StartInfo.CreateNoWindow = true;
p.Start();
string Response = p.StandardOutput.ReadToEnd();
EventLog.WriteEntry(Response);
if (Response == null || Response == "")
{
EventLog.WriteEntry("Error");
}
私はp.StandardInput.WriteLine( "Y")を試しました。とあなたの方法は、両方が動作しません – lankitha
私は私の答えを更新しました – Steve