나는 C# service를 사용하여 사용자의 특정 폴더를 차단하려고합니다. 즉, 서비스가 차단되었거나 차단되었지만 서비스를 시작하면 최종 결과는 차단 된 폴더입니다. 나는 코드를 작성했다. 하지만 응답은 확실합니까? 당신은 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