The specific problem is this: I use the following this section of the code to obtain hard disk information into the EXE file, when testing on the machine, there is a direct double-click Run and run as administrator, the result is not the same situation, how to solve this problem?
1 Public StaticString Gethardwareid ()2 {3String num =NULL;4List<string> Hdids =Newlist<string>();5ManagementClass MC =NewManagementClass ("Win32_physicalmedia");6Managementobjectcollection MOC =MC. GetInstances ();7 foreach(varIteminchMOC)8 {9String Hdid = (string) Item. properties["serialnumber"]. Value.tostring ();Ten if(!string. IsNullOrEmpty (Hdid)) {hdids. ADD (Hdid); } One } A for(inti =0; I < Hdids. Count; i++) -{num + = Hdids[i]. ToString (). Replace (" ",""); } - returnnum; the}
The resulting result is this:
C # get the hard drive serial number problem help