如何在安装程序中使用 subinacl ? C# 设置项目

发布于 2024-12-11 04:43:18 字数 1113 浏览 3 评论 0原文

我想向用户/所有人授予我的服务权限。我可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情感失落者 2024-12-18 04:43:19

我使用 Process 并成功完成了任务。感谢大家。

I used Process and got things done successfully. Thanks to all.

流星番茄 2024-12-18 04:43:18

将用户名和密码设置为空将意味着“每个用户”,除了“用户”之外的每个帐户(我的意思是: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

例如:

namespace WindowsService
{
    [RunInstaller(true)]
    public class WindowsServiceInstaller : Installer
    {
        public WindowsServiceInstaller()
        {
            ServiceProcessInstaller serviceProcessInstaller = 
                               new ServiceProcessInstaller();
            ServiceInstaller serviceInstaller = new ServiceInstaller();

            serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
            serviceProcessInstaller.Username = null;
            serviceProcessInstaller.Password = null;

            serviceInstaller.DisplayName = "My New C# Windows Service";
            serviceInstaller.StartType = ServiceStartMode.Automatic;

            serviceInstaller.ServiceName = "My Windows Service";

            this.Installers.Add(serviceProcessInstaller);
            this.Installers.Add(serviceInstaller);
        }
    }
}

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:

namespace WindowsService
{
    [RunInstaller(true)]
    public class WindowsServiceInstaller : Installer
    {
        public WindowsServiceInstaller()
        {
            ServiceProcessInstaller serviceProcessInstaller = 
                               new ServiceProcessInstaller();
            ServiceInstaller serviceInstaller = new ServiceInstaller();

            serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
            serviceProcessInstaller.Username = null;
            serviceProcessInstaller.Password = null;

            serviceInstaller.DisplayName = "My New C# Windows Service";
            serviceInstaller.StartType = ServiceStartMode.Automatic;

            serviceInstaller.ServiceName = "My Windows Service";

            this.Installers.Add(serviceProcessInstaller);
            this.Installers.Add(serviceInstaller);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文