如何在安装程序中使用 subinacl ? C# 设置项目
我想向用户/所有人授予我的服务权限。我可以使用 subinacl 授予此类权限,但不知道如何在 Installer 类中为其编码?
另外,如果我想向计算机上的每个用户授予权限,我可以使用“Everyone”作为用户吗?
什么是系统没有任何用户-我的意思是在XP上没有任何用户,那么如何处理同样的情况。
请尽早帮助我。非常感谢任何帮助。
编辑: 为了授予权限,我发现了这个: http://ss64.com/nt/subinacl.html 和这个。我尝试了cmd,成功了。 我写了以下内容来实现它:
WshShell shell = new WshShellClass();
object wf = IWshRuntimeLibrary.WshWindowStyle.WshHide;
//object ws = IWshRuntimeLibrary.
if (allusers)
shell.Run("subinacl /SERVICE \"OpenVPNService\" /Grant=Everyone=TO", ref wf, true);
else
shell.Run("subinacl /SERVICE \"OpenVPNService\" /Grant="+ Environment.UserName +"=TO", ref wf, true);
shell = null;
最后一个参数给出了问题。我只需要传递一个引用对象。代表是否显示窗口。 检查此处 我收到错误“参数3:无法从“bool”转换为“ref object”。知道在第三个参数中给出什么。
I want to grant a permission to my service to user/everyone. I can use subinacl to grant such permissions but am not usre how to code for it in the Installer class ?
And also if I want to grant permission to every user on the comp, can I use "Everyone" as user?
What is the system doesn't have any users - I mean on XP without any users, then how to handle the same.
Please help me at the earliest. Any help is highly appreciated.
EDIT :
To grant permission I found this : http://ss64.com/nt/subinacl.html and this . I tried on cmd and it worked.
I wrote the following to make it happen :
WshShell shell = new WshShellClass();
object wf = IWshRuntimeLibrary.WshWindowStyle.WshHide;
//object ws = IWshRuntimeLibrary.
if (allusers)
shell.Run("subinacl /SERVICE \"OpenVPNService\" /Grant=Everyone=TO", ref wf, true);
else
shell.Run("subinacl /SERVICE \"OpenVPNService\" /Grant="+ Environment.UserName +"=TO", ref wf, true);
shell = null;
The last parameter is giving problem. I needto pass a ref obj only. And it represents to show the window or not. Check Here I get error "Argument 3: cannot convert from 'bool' to 'ref object'. Any idea what to give in 3rd parameter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用 Process 并成功完成了任务。感谢大家。
I used Process and got things done successfully. Thanks to all.
将用户名和密码设置为空将意味着“每个用户”,除了“用户”之外的每个帐户(我的意思是:LocaSystem、LocalService、NetworkService)。或者 MSDN 是这样说的:
http://msdn.microsoft。 com/en-us/library/system.serviceprocess.serviceprocessinstaller.account.aspx
http://msdn.microsoft.com/en-us/library/system .serviceprocess.serviceaccount.aspx
例如:
Setting Username and Password to null will mean "every user" in case of every account except "User" (I mean: LocaSystem, LocalService, NetworkService). Or so MSDN says:
http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceprocessinstaller.account.aspx
http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceaccount.aspx
For example: