Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:00:37+00:00 2026-06-04T04:00:37+00:00

Do you have any idea how can I add a user in Local policies?

  • 0

Do you have any idea how can I add a user in Local policies? I need same effect like this

gpedit.msc -> Computer Configuration / Windows Settings / Security Settings / Local Policies / User Rights Assignment / “Access this computer from the network”

I would like to do that by adding a registry key or by running a command from cmd. If you have any hint or internet resource to share, I would be happy.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:00:39+00:00Added an answer on June 4, 2026 at 4:00 am

    Here’s one I prepared earlier. We use the (lengthy, sorry) wrapper class below to grant “Logon as a service right”. The call for this is as follows:

    var identity = new WindowsIdentity(logonName);
    LsaSecurityWrapper.AddAccountRights(identity.User.AccountDomainSid,
        "SeServiceLogonRight");
    

    You would just need to replace “SeServiceLogonRight” with your own. A quick Google tells me this should be “SeNetworkLogonRight”. If you want this in a console app, then you can quickly compile one. Set your Main method like so:

    static void Main(string[] args)
    {
        var identity = new WindowsIdentity(args[0]);
        LsaSecurityWrapper.AddAccountRights(identity.User.AccountDomainSid, args[1]);
    }
    

    Then call as YourConsoleApp.exe logon right. Here’s the wrapper:

    [StructLayout(LayoutKind.Sequential)]
    internal struct LSA_OBJECT_ATTRIBUTES
    {
        internal int Length;
        internal IntPtr RootDirectory;
        internal IntPtr ObjectName;
        internal int Attributes;
        internal IntPtr SecurityDescriptor;
        internal IntPtr SecurityQualityOfService;
    }
    
    /// 
    /// LSA_UNICODE_STRING structure
    /// 
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    internal struct LSA_UNICODE_STRING
    {
        internal ushort Length;
        internal ushort MaximumLength;
        [MarshalAs(UnmanagedType.LPWStr)] internal string Buffer;
    }
    
    /// 
    /// Wraps LsaAddAccountRights call.
    /// 
    public sealed class LsaSecurityWrapper
    {
        [DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true),
         SuppressUnmanagedCodeSecurityAttribute]
        internal static extern uint LsaOpenPolicy(
            LSA_UNICODE_STRING[] SystemName,
            ref LSA_OBJECT_ATTRIBUTES ObjectAttributes,
            int AccessMask,
            out IntPtr PolicyHandle
            );
    
        [DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true),
         SuppressUnmanagedCodeSecurityAttribute]
        internal static extern uint LsaAddAccountRights(
            LSA_HANDLE PolicyHandle,
            IntPtr pSID,
            LSA_UNICODE_STRING[] UserRights,
            int CountOfRights
            );
    
        [DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true),
         SuppressUnmanagedCodeSecurityAttribute]
        internal static extern uint LsaRemoveAccountRights(
            LSA_HANDLE PolicyHandle,
            IntPtr AccountSid,
            bool AllRights,
            LSA_UNICODE_STRING[] UserRights,
            int CountOfRights
            );
    
        [DllImport("advapi32")]
        internal static extern int LsaClose(IntPtr PolicyHandle);
    
        private enum Access : int
        {
            POLICY_READ = 0x20006,
            POLICY_ALL_ACCESS = 0x00F0FFF,
            POLICY_EXECUTE = 0X20801,
            POLICY_WRITE = 0X207F8
        }
    
        // rights: (http://msdn.microsoft.com/en-us/library/bb545671(VS.85).aspx)
        public static void AddAccountRights(SecurityIdentifier sid, string rights)
        {
            IntPtr lsaHandle;
    
            LSA_UNICODE_STRING[] system = null;
            LSA_OBJECT_ATTRIBUTES lsaAttr;
            lsaAttr.RootDirectory = IntPtr.Zero;
            lsaAttr.ObjectName = IntPtr.Zero;
            lsaAttr.Attributes = 0;
            lsaAttr.SecurityDescriptor = IntPtr.Zero;
            lsaAttr.SecurityQualityOfService = IntPtr.Zero;
            lsaAttr.Length = Marshal.SizeOf(typeof(LSA_OBJECT_ATTRIBUTES));
            lsaHandle = IntPtr.Zero;
    
            uint ret = LsaOpenPolicy(system, ref lsaAttr, (int)Access.POLICY_ALL_ACCESS, out lsaHandle);
            if (ret == 0)
            {
                Byte[] buffer = new Byte[sid.BinaryLength];
                sid.GetBinaryForm(buffer, 0);
    
                IntPtr pSid = Marshal.AllocHGlobal(sid.BinaryLength);
                Marshal.Copy(buffer, 0, pSid, sid.BinaryLength);
    
                LSA_UNICODE_STRING[] privileges = new LSA_UNICODE_STRING[1];
    
                LSA_UNICODE_STRING lsaRights = new LSA_UNICODE_STRING();
                lsaRights.Buffer = rights;
                lsaRights.Length = (ushort)(rights.Length * sizeof(char));
                lsaRights.MaximumLength = (ushort)(lsaRights.Length + sizeof(char));
    
                privileges[0] = lsaRights;
    
                ret = LsaAddAccountRights(lsaHandle, pSid, privileges, 1);
    
                LsaClose(lsaHandle);
    
                Marshal.FreeHGlobal(pSid);
    
                if (ret != 0)
                {
                    throw new Win32Exception("LsaAddAccountRights failed with error code: " + ret);
                }
            }
            else
            {
                throw new Win32Exception("LsaOpenPolicy failed with error code: " + ret);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't have any idea how can I create a custom UIPickerView with an
Does anyone have any idea on how can you create a product filtering query
Does anyone have any idea if you can find source JARs on Maven repositories?
does any of you have any info/idea on how can I test my application
Does any one have any idea why this would be happening? This is some
Do You have any idea how to easily add a menu link Change Your
I want to add this facility into my app in which user can set
Anyone have any idea why my jQuery carousel is working fine at the bottom
Anyone have any idea how to connect to their FTP server? I am using
Anyone have any idea how I would go about converting a timestamp in milliseconds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.