none
ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia") throw a exception RRS feed

  • Question

  • I use "ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")" to get the harddisk's serial number,but it throw a exception,detail follow:

    {System.Runtime.InteropServices.COMException (0x80040154): 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))
    在 System.Management.ThreadDispatch.Start()
    在 System.Management.ManagementScope.Initialize()
    在 System.Management.ManagementObjectSearcher.Initialize()
    在 System.Management.ManagementObjectSearcher.Get()
    在 CVTouch.Service.GetHardDiskID.GetHDID() 位置 F:\IIPcode\NM2009\Code\Service\GetHardDiskID.cs:行号 14}

    System.Runtime.InteropServices.COMException was caught
    Message=没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))
    Source=System.Management
    ErrorCode=-2147221164
    StackTrace:
    在 System.Management.ThreadDispatch.Start()
    在 System.Management.ManagementScope.Initialize()
    在 System.Management.ManagementObjectSearcher.Initialize()
    在 System.Management.ManagementObjectSearcher.Get()
    在 CVTouch.Service.GetHardDiskID.GetHDID() 位置 F:\IIPcode\NM2009\Code\Service\GetHardDiskID.cs:行号 14
    InnerException:

    Thursday, August 25, 2011 6:59 AM

Answers

All replies

  • What operating system are you using?
    Thursday, August 25, 2011 12:01 PM
    Moderator
  • WMI FAQ: Why does my script run on one version of Windows but not on another?

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    • Marked as answer by Paul Zhou Friday, September 2, 2011 6:51 AM
    Friday, August 26, 2011 12:18 AM
  • Did you try the query with Wbemtest? If it works, then the problem is with your code only. Meanwhile, instead of ManagementObjectSearcher, try using managementClass.

    ManagementClass wmi = new ManagementClass("Win32_PhysicalMedia");
    foreach (var item in wmi.GetInstances())
    {
         string serialNumber = Convert.ToString(item["SerialNumber"]);
    }
    

    Please mark this post as answer if it solved your problem. Happy Programming!
    Saturday, August 27, 2011 5:04 AM
  •  

    Hi,

     

    Has your issue been resolved? Would you mind letting us know the result of the suggestions?

     

    Now I will mark an answer, you can mark others that you think to be so useful to your issue.

    If you still have any questions about this issue, please feel free to let me know. We will continue to work with you on this issue.

     

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, September 2, 2011 6:52 AM
  • Thank you. My issue had beed resolved.
    Tuesday, May 29, 2012 2:56 AM