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 7669469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:36:10+00:00 2026-05-31T15:36:10+00:00

I have a .net program that requests admin privileges by default whenever I try

  • 0

I have a .net program that requests admin privileges by default whenever I try to run it. I don’t know of any reason it NEEDS these privileges in my specific case, so I simply suspect lazy programming behind it (enforcing admin acces just in case it might eventually need it).

Is there any way I can force it to not try to elevate and run with the regular access rights? E.g. by modifying the embedded manifest or through some programmatic ways?

Running a regular app as administrator is pretty trivial, but is the reverse even possible?

Update:
I only have access to the compiled .exe, not to the source code or original manifest file. I’ve had a look at the embedded manifest of the .exe through ManifestView by Kenny Kerr and it definitely requests admin privileges as it includes the following:

<requestedPrivileges>
    <requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>

Is there any way to change the manifest of a compiled .exe assembly? E.g. any tool around to do that or info about how to do that programmatically?

  • 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-05-31T15:36:11+00:00Added an answer on May 31, 2026 at 3:36 pm

    I tried to create a small C# app to modify the embedded manifest so it wouldn’t request admin privileges. This is the solution I finally came up with, making a bunch of Win32 calls to extract the manifest and replace an existing manifest. It’s already long enough, so I omitted the part where I actually modify the manifest (just some basic XML operations).

    There are two static methods here: LoadManifestResource, which loads the string representation of the embedded manifest of an executable and SaveManifestResource, which saves the string representation of a manifest resource in the specified executable, overwriting the old one.

    This is a quick and dirty solution which worked just fine for me, but might very well not work in every case.

    public static class Library
    {
        [DllImport("kernel32.dll")]
        static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags);
    
        [DllImport("kernel32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool FreeLibrary(IntPtr hModule);
    
        [DllImport("kernel32.dll")]
        static extern IntPtr FindResource(IntPtr hModule, int lpName, int lpType);
    
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern IntPtr LoadResource(IntPtr hModule, IntPtr hResInfo);
    
        [DllImport("kernel32.dll")]
        static extern IntPtr LockResource(IntPtr hResData);
    
        [DllImport("Kernel32.dll", EntryPoint = "SizeofResource", SetLastError = true)]
        private static extern uint SizeofResource(IntPtr hModule, IntPtr hResource);
    
        [System.Flags]
        enum LoadLibraryFlags : uint
        {
            DONT_RESOLVE_DLL_REFERENCES = 0x00000001,
            LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010,
            LOAD_LIBRARY_AS_DATAFILE = 0x00000002,
            LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040,
            LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020,
            LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008
        }
    
        public static unsafe string LoadManifestResource(string fileName)
        {
            // load library to retrieve manifest from
            var libraryHandle = LoadLibraryEx(fileName, IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE);
            if (libraryHandle.ToInt32() == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "couldn't load library");
            }
            try
            {
                // find manifest
                var resource = FindResource(libraryHandle, 1, 24);
                if (resource.ToInt32() == 0)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error(), "couldn't find manifest resource");
                }
    
                // load manifest
                var loadedManifest = LoadResource(libraryHandle, resource);
                if (loadedManifest.ToInt32() == 0)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error(), "couldn't load manifest resource");
                }
    
                // lock manifest
                var lockedManifest = LockResource(loadedManifest);
                if (lockedManifest.ToInt32() == 0)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error(), "couldn't lock manifest resource");
                }
    
                // calculate size of manifest, copy to byte array and convert to string
                int manifestSize = (int)SizeofResource(libraryHandle, resource);
    
                byte[] data = new byte[manifestSize];
                Marshal.Copy(lockedManifest, data, 0, manifestSize);
                var manifest = Encoding.UTF8.GetString(data);
    
                return manifest;
            }
            finally
            {
                FreeLibrary(libraryHandle);
            }
        }
    
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern IntPtr BeginUpdateResource(string pFileName,
           [MarshalAs(UnmanagedType.Bool)]bool bDeleteExistingResources);
    
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool UpdateResource(IntPtr hUpdate, string lpType, string lpName, ushort wLanguage, IntPtr lpData, uint cbData);
    
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool UpdateResource(IntPtr hUpdate, int lpType, int lpName, ushort wLanguage, IntPtr lpData, uint cbData);
    
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool EndUpdateResource(IntPtr hUpdate, bool fDiscard);
    
        public static unsafe void SaveManifestResource(string file, string manifest)
        {
            var hUpdate = BeginUpdateResource(file, false);
    
            byte[] bytes = Encoding.UTF8.GetBytes(manifest);
            IntPtr ptr = Marshal.AllocHGlobal(bytes.Length);
            try
            {
                Marshal.Copy(bytes, 0, ptr, bytes.Length);
    
                if (!UpdateResource(hUpdate, 24, 1, 0, ptr, (uint)bytes.Length))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
    
                if (!EndUpdateResource(hUpdate, false))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C#/.NET program that can run both as a console application and
I have a .Net program that I want to install on a terminal server.
I have a .NET program and a Borland Win32 program that need to pass
I have a VB.NET program that I wish to to publish. In the code
I have a vb .net program that exports information to certain fields of an
I have a vb.net program that uses mysql as its database. And it works
I have a clock feature in a VB.NET program that displays the time including
I have a VB6 program that someone recently helped me convert to VB.NET In
We have a NET app that gets installed to the Program Files folder. The
I have an ASP.NET web service that I can access via a windows program

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.