我想用c#服務阻止用戶的某個文件夾。這意味着當您啓動服務時雖然它被阻止,但最終結果是阻止的文件夾。我寫了一個代碼。但回覆是你確定嗎?請幫忙解決這個如何在C#窗口服務中使用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 2012-03-08 09:21:35
我已經更新了我的答案 – Steve 2012-03-08 09:29:10