Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在安装程序中使用subinacl?C安装项目_C#_Permissions_Installation_Setup Project_Grant - Fatal编程技术网

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

C# 如何在安装程序中使用subinacl?C安装项目,c#,permissions,installation,setup-project,grant,C#,Permissions,Installation,Setup Project,Grant,我想向用户/所有人授予我的服务权限。我可以使用subinacl来授予这样的权限,但不知道如何在Installer类中为其编码 而且,如果我想向公司上的每个用户授予权限,我可以使用每个人作为用户吗 什么是系统没有任何用户-我的意思是在XP上没有任何用户,那么如何处理相同的问题 请尽早帮助我。非常感谢您的帮助 编辑: 为了授予许可,我发现了这个:和。我试了一下cmd,效果很好。 为了实现这一目标,我写了以下内容: WshShell shell = new WshShellClass(

我想向用户/所有人授予我的服务权限。我可以使用subinacl来授予这样的权限,但不知道如何在Installer类中为其编码

而且,如果我想向公司上的每个用户授予权限,我可以使用每个人作为用户吗

什么是系统没有任何用户-我的意思是在XP上没有任何用户,那么如何处理相同的问题

请尽早帮助我。非常感谢您的帮助

编辑: 为了授予许可,我发现了这个:和。我试了一下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;

最后一个参数是给定问题。我只需要通过ref obj。它表示是否显示窗口。我得到错误参数3:无法从'bool'转换为'ref object'。知道在第三个参数中给出什么吗

将用户名和密码设置为null将意味着每个帐户中的每个用户,但用户除外。我的意思是:LocaSystem、LocalService、NetworkService。至少MSDN是这么说的:

例如:

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);
        }
    }
}

我使用了这个过程,成功地完成了事情。感谢大家。

Arie,我使用的服务是第三方服务,我对此无能为力。在安装应用程序之前,我只需确保它已安装在comp上。因此,我认为上述内容对我没有用处。该服务是自定义安装的,所以它在注册表中的1访问条目也没有完成,我可以更改。我发现了这个Arie,该代码也需要权限-请查看@tunger的帖子。我已经添加了我曾经处理过的代码。我被卡住了。