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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:59:28+00:00 2026-06-01T14:59:28+00:00

My user is an Administrator (I see it in the configuration panel), the below

  • 0

My user is an Administrator (I see it in the configuration panel), the below code throws a Win32Exception in which it says Access Denied, how can I change this (Win7 32 bits) ?

static Guid VideoGuid = new Guid("4d36e968-e325-11ce-bfc1-08002be10318");

[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
static void Main(string[] args)
{
    SafeDeviceHandle handle = null;
    try
    {
        handle = NativeMethods.SetupDiGetClassDevs(ref VideoGuid, IntPtr.Zero, IntPtr.Zero, NativeMethods.DIGCF.PRESENT);
        var data = new NativeMethods.SP_DEVINFO_DATA().Initialize();
        var param = new NativeMethods.SP_PROPCHANGE_PARAMS().Initialize();
        param.ClassInstallHeader.InstallFunction = 0x12;
        param.StateChange = NativeMethods.DICS.ENABLE; // 0x01
        param.Scope = NativeMethods.DICS_GLOBAL.GLOBAL; // 0x01
        param.HwProfile = 0;

        RunWin32Method(() => NativeMethods.SetupDiEnumDeviceInfo(handle, 0u, out data));
        RunWin32Method(() => NativeMethods.SetupDiSetClassInstallParams(handle, ref data, ref param, (UInt32)Marshal.SizeOf(param)));
        RunWin32Method(() => NativeMethods.SetupDiChangeState(handle, ref data));
    }
    catch
    {
        var w = new Win32Exception(Marshal.GetLastWin32Error());
    }
    finally
    {
        if (handle != null && (!handle.IsInvalid))
            handle.Close();
    }
}

static void RunWin32Method(Func<bool> f)
{
    if (!f())
    {
        Debug.WriteLine(new Win32Exception(Marshal.GetLastWin32Error()).Message);
    }
}

If you want more code, just ask 🙂

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-01T14:59:30+00:00Added an answer on June 1, 2026 at 2:59 pm

    Recapping the comment trail, a user in the Administrator group doesn’t have admin rights on Vista/Server 2008 and later unless the process runs elevated. A manifest is required to get Windows to display the UAC elevation prompt.

    This cannot work for programs that are started at login by the Run registry key or the Startup folder. Windows refuses to display the elevation prompt because the user cannot accurately guess exactly what program asked for the elevation. Code-signing the program with a certificate may fix this since that permits Windows to verify and display the program owner, never actually tried that.

    Workarounds for such programs are activating it as a service or a scheduled task. Neither of which requires the manifest. The theory behind this seeming oddity is that it already requires elevation to get a service or scheduled task installed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On a Vista dev machine I used this code successfully to change user Administrator
can I use it like this in View? <%= Html.CheckBoxFor(user => user.Role, Administrator)%> and
I am maintaining an application which currently checks to see whether MS Access 2007
I'm trying to run a process as a different user that has Administrator privilege
I have a few doubts about this robots file. User-agent: * Disallow: /administrator/ Disallow:
How Do I deploy applications so that they require administrator rights without the end-user
I have the following enum: [Flags] public enum PermissionLevel { User = 1, Administrator
I have MOSS. I want to make a page where a user, say administrator,
I have a Silverlight web app which uses ASP.net Website administration tool for user
I have a simple create user wizard and custom membership provider which was taken

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.