简体   繁体   中英

different results for web and desktop applications for same code

I have the following piece of code.

It is returning different results when running on the same machine in case of web and desktop applications.

Here is my code. Please guide me on what to do regarding this???

    var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

    return (from ManagementObject wmiHD in searcher.Get()
            select wmiHD["SerialNumber"] == null ? "VM HD" : wmiHD["SerialNumber"].ToString()).ToList();

Here is a LINQ-free version of the same code

    var hdCollection = new List<string>();
    var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

    foreach (ManagementObject wmiHD in searcher.Get())
    {
        // get the hardware serial no.
        if (wmiHD["SerialNumber"] == null)
        {
            hdCollection.Add("VM HD");
        }
        else
        {
            hdCollection.Add(wmiHD["SerialNumber"].ToString());
        }
    }
    return hdCollection;

That could possibly be caused by two things:

Both actions can compromise security, but the first one gives more choices to fix this by setting ACLs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM