System. Management. managementexception: Access Denied Solution

Source: Internet
Author: User

Solution: Principle: The page (related to IIS) has a lower permission than the DLL running permission. It is estimated that Microsoft is designed to take into account what hackers will exploit this vulnerability. You only need to obtain this value before running the page. The complete code is as follows: /// <summary> /// obtain cpuid /// </Summary> /// <returns> </returns> Public static string getcpuid () {string cpuid = NULL; managementclass mclass = new managementclass ("win32_processor"); try {managementobjectcollection MOC = mclass. getinstances ();

Foreach (managementobject Mo in MoC) {cpuid = Mo. properties ["processorid"]. value. tostring (); break;} catch (exception ex) {cpuid = ex. tostring ();} If (system. web. httpcontext. current. application ["cpuid"] = NULL) {system. web. httpcontext. current. application. lock (); system. web. httpcontext. current. application ["cpuid"] = cpuid; system. web. httpcontext. current. application. unlock ();} return cpuid ;}
On the page, call the cpuid value: system. web. httpcontext. current. application ["cpuid"]. tostring (); the premise of running is that the Code must be run before the page is executed, for example, the code is executed first in the httpmodules program.
Finally, paste the running effect:
-------------- The page starts before calling ------------ cpuid value: bfebfbff00000f29 -------------- the page ends before calling --------------
-------------- Page call

Start with -------------- cpuid value: system. management. managementexception: access is denied in system. management. managementexception. throwwithextendedinfo (managementstatus errorcode) in system. management. managementscope. initializeguts (Object O) in system. management. managementscope. initialize () in system. management. managementobject. initialize (Boolean GetObject) in system. management. managementclass. getinstances (enumerationoptions options) in system. management. managementclass. getinstances () in managementtest. class1.getcpuid () -------------- page call ends --------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.