zoukankan      html  css  js  c++  java
  • System.Management.ManagementException: 访问遭到拒绝的解决方案 dodo

    解决方案: 原理:页面(与IIS有关)运行的权限低于DLL运行的权限,估计是微软考虑到什么黑客会利用此漏洞而设计的。只要在运行页面前把这个值获取就没问题。 结果整理了一下,完整代码如下:  /// <summary>         /// 获取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;         }
    在页面调用CPUID值: System.Web.HttpContext.Current.Application["CPUID"].ToString(); 运行的前提是必须把这个代码在页面执行前运行,如加在 httpModules 里程序一开始就先执行这个代码。
    最后贴上运行效果:
    --------------页面调用前开始-------------- CPUID值:BFEBFBFF00000F29 --------------页面调用前结束--------------
    --------------页面调

    用开始-------------- CPUID值:System.Management.ManagementException: 访问遭到拒绝 在 System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) 在 System.Management.ManagementScope.InitializeGuts(Object o) 在 System.Management.ManagementScope.Initialize() 在 System.Management.ManagementObject.Initialize(Boolean getObject) 在 System.Management.ManagementClass.GetInstances(EnumerationOptions options) 在 System.Management.ManagementClass.GetInstances() 在 ManagementTest.Class1.GetCpuId() --------------页面调用结束--------------

  • 相关阅读:
    C语言函数sscanf()的用法(转)
    GDB基本命令(整合)(转)
    单元命中率与字节命中率
    rpm安装找不到.so库文件(linux动态库连接的相关知识)(转)
    Linux下的tar压缩解压缩命令详解(转)
    Linux系统如何查看版本信息
    Linux /bin, /sbin, /usr/bin, /usr/sbin 区别(转)
    rsync问题-connection refused(111)、Unknown module
    转: 浅析Fusion-IO和Intel SSD
    转: 从0到1的电商架构应该怎么做?
  • 原文地址:https://www.cnblogs.com/zgqys1980/p/3108070.html
Copyright © 2011-2022 走看看