C# 命令行 SetACL
我正在尝试解决文件夹所有者的问题。我正在使用 SetACL。我可以使用 cmd 并使参数起作用,但是当我尝试将其添加到程序中时......它不起作用。我设置了一个断点来确保参数正确传递,确实如此。欢迎任何帮助。
Process p = new Process();
if (Wow.Is64BitOperatingSystem == true)
{
p.StartInfo.FileName = "SetACLx64.exe";
}
else
{
p.StartInfo.FileName = "SetACLx86.exe";
}
string command = @" -on """ + path +
@""" -ot file -actn setprot -op ""dacl:np;sacl:nc"" -actn setowner -ownr ""n:" + account + @";"" -rec cont_obj";
p.StartInfo.Arguments = command;
p.Start();
我已经让它在同一个程序中正常工作以解决注册表问题。只是无法让这个例子发挥作用。我尝试设置的文件夹是 %temp%
文件夹。
I'm trying to fix an issue with the owner on a folder. I am using SetACL. I can use cmd and make the arguments work, but when I try adding it to a program...it doesn't work. I've set a break point to ensure the argument is passed right and it was. Any help is welcome.
Process p = new Process();
if (Wow.Is64BitOperatingSystem == true)
{
p.StartInfo.FileName = "SetACLx64.exe";
}
else
{
p.StartInfo.FileName = "SetACLx86.exe";
}
string command = @" -on """ + path +
@""" -ot file -actn setprot -op ""dacl:np;sacl:nc"" -actn setowner -ownr ""n:" + account + @";"" -rec cont_obj";
p.StartInfo.Arguments = command;
p.Start();
I have got this to work in the same program for a registry issue without trouble. Just can't get this example to work. Folder I'm try to set is the %temp%
folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它按照 Sanjeevakumar 的要求以管理员身份运行,则
尝试删除命令变量中的第一个空格。 Arguments 参数不需要您为参数提供初始空间。可能这会导致问题。
还可以尝试通过在调用 Start() 方法之前添加以下行来利用进程的错误数据。
然后定义事件处理程序。
If it is running as admin as Sanjeevakumar asked then
Try removing the first space in your command variable. The Arguments parameter does not require that you provide an initial space for the arguments. May be that causes the problem.
Also try tapping into the error data of your process by adding the following lines before calling the Start() method.
And then define the event handler.
那么当路径为“%temp%”时,您的代码不起作用?在这种情况下,解决方案很简单:变量扩展不是由 SetACL 完成的,而是由 SetACL 启动之前的命令 shell 完成的。如果直接启动 SetACL 而不调用 cmd.exe,则永远不会发生变量扩展。
您有两个选择:
So your code does not work when path is "%temp%"? In that case the solution is simple: variable expansion is not done by SetACL but the command shell before SetACL is even started. If you start SetACL directly without invoking cmd.exe then variable expansion never takes place.
You have two options: