C # get a hard disk serial number

xiaoxiao2021-03-06  66

Using system; using system.runtime.interopservices;

Namespace arli.commonprj {

#region how use this? / * string svol = getVol.getvolof ("c"); * / #ndregion

Public class getvol {

[DllImport ( "kernel32.dll")] private static extern int GetVolumeInformation (string lpRootPathName, string lpVolumeNameBuffer, int nVolumeNameSize, ref int lpVolumeSerialNumber, int lpMaximumComponentLength, int lpFileSystemFlags, string lpFileSystemNameBuffer, int nFileSystemNameSize);

Public Static String GetVolof (String DRVID) {const INT MAX_FILENAME_LEN = 256; int RETVAL = 0; INT A = 0; int b = 0; string str1 = null; string str2 = null;

INT i = GetVolumeInformation (drvid @ ": /", str1, max_filename_len, ref reledval, a, b, str2, max_filename_len;

Return RetVal.Tostring ("x");}}}

转载请注明原文地址:https://www.9cbs.com/read-119912.html

New Post(0)