Make(delphi) ver(4.04 build 185) Add(MainForm,10300148,182,91) { Width=445 Height=170 Caption="FlashSerialNumber" Position=1 } Add(Label,4762534,126,91) { Left=10 Top=100 Width=117 Height=24 Font=[MS Sans Serif,12,1,0,1] Caption="SerialNumber:" } Add(Label,7459882,511,147) { Left=135 Top=100 Width=287 Height=24 Font=[MS Sans Serif,12,1,128,1] Caption="" AutoSize=1 Alignment=2 } Add(FSMonitor,11489012,182,147) { link(onDeviceArrival,14258092:doGetSerialNum,[]) link(onDeviceRemoveComplete,13602256:doData,[(242,160)(242,202)]) } Add(DoData,13602256,252,196) { Data=String() link(onEventData,2891511:doEvent1,[]) } Add(InlineCode,14258092,252,147) { @Hint=#22:Выводит серийный номер|28:флеш-диска по букве драйвера| WorkPoints=#14:doGetSerialNum| EventPoints=#14:onGetSerialNum| DataPoints=#5:Drive| Code=#15:unit HiAsmUnit;|0:|9:interface|0:|29:uses kol,Share,Debug,Windows;|0:|5:const|34: ANYSIZE_ARRAY = 1;|83: DIGCF_DEFAULT = $00000001; // only valid with DIGCF_DEVICEINTERFACE|42: DIGCF_PRESENT = $00000002;|42: DIGCF_ALLCLASSES = $00000004;|42: DIGCF_PROFILE = $00000008;|42: DIGCF_DEVICEINTERFACE = $00000010;|42: RegDisposition_OpenExisting = $00000001;|0:|4:type|26: REGDISPOSITION = ^ULONG;|25: ULONG_PTR = DWORD;|27: DEVINST = DWORD; |27: HDEVINFO = Pointer;|0:|35: PSPDevInfoData = ^TSPDevInfoData;|33: SP_DEVINFO_DATA = packed record|18: cbSize: DWORD;|21: ClassGuid: TGUID;|37: DevInst: DWORD; // DEVINST handle|24: Reserved: ULONG_PTR;|6: end;|35: TSPDevInfoData = SP_DEVINFO_DATA;|4: |49: PSPDeviceInterfaceData=^TSPDeviceInterfaceData;|40: SP_DEVICE_INTERFACE_DATA=packed record|18: cbSize: DWORD;|30: InterfaceClassGuid: TGUID;|17: Flags: DWORD;|24: Reserved: ULONG_PTR;|6: end;|50: TSPDeviceInterfaceData=SP_DEVICE_INTERFACE_DATA;|0:|63: PSPDeviceInterfaceDetailDataA=^TSPDeviceInterfaceDetailDataA;|61: PSPDeviceInterfaceDetailData=PSPDeviceInterfaceDetailDataA;|49: SP_DEVICE_INTERFACE_DETAIL_DATA_A=packed record|18: cbSize: DWORD;|57: DevicePath: array [0..ANYSIZE_ARRAY - 1] of AnsiChar;|6: end;|66: TSPDeviceInterfaceDetailDataA=SP_DEVICE_INTERFACE_DETAIL_DATA_A;|61: TSPDeviceInterfaceDetailData=TSPDeviceInterfaceDetailDataA;|0:|4:type|27:THiAsmClass = class(TDebug)|0:|9: private|69: function GetFlashSerialFromDrive(const Drive:string): string; |8: public|10: Drive,|30: onGetSerialNum: THI_Event;|58: procedure doGetSerialNum(var _Data:TData; Index:Word);|6: end;|0:|14:implementation|16:uses hiStr_Enum;|0:|71:function GetVolumeNameForVolumeMountPoint(lpszVolumeMountPoint: LPCSTR;|62: lpszVolumeName: LPSTR; cchBufferLength: DWORD): BOOL;|77: stdcall; external kernel32 name 'GetVolumeNameForVolumeMountPointA';|0:|75:function SetupDiGetClassDevs(ClassGuid: PGUID; const Enumerator: PAnsiChar;|51: hwndParent: HWND; Flags: DWORD): HDEVINFO;|69: stdcall; external'SetupApi.dll' name 'SetupDiGetClassDevsA';|0:|61:function SetupDiEnumDeviceInterfaces(DeviceInfoSet: HDEVINFO;|73: DeviceInfoData: PSPDevInfoData; const InterfaceClassGuid: TGUID;|84: MemberIndex: DWORD; var DeviceInterfaceData: TSPDeviceInterfaceData): BOOL;|77: stdcall; external 'SetupApi.dll' name 'SetupDiEnumDeviceInterfaces';|0:|66:function SetupDiGetDeviceInterfaceDetailA(DeviceInfoSet: HDEVINFO;|53: DeviceInterfaceData: PSPDeviceInterfaceData;|65: DeviceInterfaceDetailData: PSPDeviceInterfaceDetailData;|71: DeviceInterfaceDetailDataSize: DWORD; var RequiredSize: DWORD;|39: Device: PSPDevInfoData): BOOL;|41: stdcall; external'SetupApi.dll';|0:|61:function SetupDiGetDeviceInstanceIdA(DeviceInfoSet: HDEVINFO;|66: DeviceInfoData: PSPDevInfoData; DeviceInstanceId: LPTSTR;|66: DeviceInstanceIdSize: DWORD; RequiredSize: PDWORD): BOOL;|41: stdcall; external'SetupApi.dll';|0:|69:function SetupDiDestroyDeviceInfoList(DeviceInfoSet: HDEVINFO): BOOL;|77: stdcall; external'SetupApi.dll' name 'SetupDiDestroyDeviceInfoList';|0:|55:function SetupDiEnumDeviceInfo(DeviceInfoSet: HDEVINFO;|71: MemberIndex: DWORD; var DeviceInfoData: TSPDevInfoData): BOOL;|50: stdcall; external'SetupApi.dll'; |0:|92:function CM_Get_Parent(var dnDevInstParent: DWORD; dnDevInst: DWORD; ulFlags: ULONG): DWORD;|41: stdcall; external'cfgmgr32.dll';|0:|68:function CM_Open_DevNode_Key(dnDevNode: DEVINST; samDesired: REGSAM;|63: ulHardwareProfile: ULONG; Disposition: REGDISPOSITION;|51: phkDevice: PHKEY; ulFlags: ULONG): DWORD; |41: stdcall; external'cfgmgr32.dll';|0:|73:function THiAsmClass.GetFlashSerialFromDrive(const Drive:string): string;|5:const|74: GUID_DEVINTERFACE_VOLUME:TGUID='{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}';|3:var|21: PnPHandle:HDEVINFO;|25: DevData:TSPDevInfoData;|45: DeviceInterfaceData:TSPDeviceInterfaceData;|55: FunctionClassDeviceData:PSPDeviceInterfaceDetailData;|15: Devn:Integer;|22: BytesReturned:DWORD;|24: MountPointName:string;|27: DeviceInstanceId: string;|0:|76: function GetVolumeNameForVolumeMountPointString(const Name:string):string;|5: var|38: Volume:array[0..MAX_PATH] of Char;|7: begin|41: FillChar(Volume[0],SizeOf(Volume),0);|76: GetVolumeNameForVolumeMountPoint(PChar(Name),@Volume[0],SizeOf(Volume));|19: Result:=Volume;|6: end;|0:|59: function ExtractSerial(const SymbolicName:string):string;|5: var|16: Count:DWORD;|19: PC,First:PChar;|7: begin|28: PC:=PChar(SymbolicName);|13: Count:=0;|15: First:=nil;|26: while PC^<>#0 do begin|27: if PC^='#' then begin|21: case Count of|24: 1:First:=PC+1;|17: 2:begin|47: SetString(Result,First,PC-First);|19: Exit;|16: end;|12: end;|19: Inc(Count);|10: end;|14: Inc(PC);|8: end;|15: Result:='';|6: end;|0:|5:begin|13: Result:='';|105: PnPHandle:=SetupDiGetClassDevs(@GUID_DEVINTERFACE_VOLUME,nil,0,DIGCF_PRESENT or DIGCF_DEVICEINTERFACE);|52: if PnPHandle<>Pointer(INVALID_HANDLE_VALUE) then ;|5: TRY|66: MountPointName:=GetVolumeNameForVolumeMountPointString(Drive);|63: DeviceInterfaceData.cbSize:=SizeOf(TSPDeviceInterfaceData);|12: Devn:=0;|105: while SetupDiEnumDeviceInterfaces(PnPHandle,nil,GUID_DEVINTERFACE_VOLUME,Devn,DeviceInterfaceData) do|9: begin|38: DevData.cbSize:=SizeOf(DevData);|23: BytesReturned:=0;|0:|100: SetupDiGetDeviceInterfaceDetailA(PnPHandle,@DeviceInterfaceData,nil,0,BytesReturned,@DevData);|75: if (BytesReturned<>0)and(GetLastError=ERROR_INSUFFICIENT_BUFFER) then|11: begin|57: FunctionClassDeviceData:=AllocMem(BytesReturned);|11: TRY|81: FunctionClassDeviceData^.cbSize:=SizeOf(TSPDeviceInterfaceDetailDataA);|143: if SetupDiGetDeviceInterfaceDetailA(PnPHandle,@DeviceInterfaceData,FunctionClassDeviceData,BytesReturned,BytesReturned,@DevData) then|15: begin|121: if GetVolumeNameForVolumeMountPointString(PChar(@FunctionClassDeviceData.DevicePath)+'\')=MountPointName then|17: begin|47: SetLength(DeviceInstanceId, 255);|106: SetupDiGetDeviceInstanceIdA(PnPHandle, @DevData, @DeviceInstanceId[1], 255, @BytesReturned);|57: SetLength(DeviceInstanceId, BytesReturned);|41: Result := DeviceInstanceId;|16: end;|14: end;|15: FINALLY|43: FreeMem(FunctionClassDeviceData);|12: END;|10: end;|16: Inc(Devn);|8: end;|9: FINALLY|44: SetupDiDestroyDeviceInfoList(PnPHandle);|6: END;|4:end;|0:|37:procedure THiAsmClass.doGetSerialNum;|3:var|15: Drv:string; |6:begin |34: Drv := ReadString(_Data, Drive);|23: Drv := Drv[1] + ':\';|59: _hi_OnEvent(onGetSerialNum,GetFlashSerialFromDrive(Drv));|4:end;|0:|4:end.| link(onGetSerialNum,7257094:doEvent1,[]) AddHint(61,-50,159,26,@Hint) } Add(Memo,8995493,511,196) { Left=10 Top=10 Width=415 } Add(Hub,2891511,315,196) { link(onEvent1,9578769:doWork3,[(473,202)]) link(onEvent2,8995493:doClear,[]) } Add(Hub,7257094,315,147) { link(onEvent1,12135062:doSplit,[]) link(onEvent2,8995493:doAdd,[(368,160)(368,188)(480,188)(480,202)]) } Add(MultiStrData,12135062,378,147) { Char="#" From=1 Count=1 Direct=1 link(onPart1,5715386:doSplit,[]) } Add(MultiStrData,5715386,427,147) { Char="&" Count=1 link(onPart1,9578769:doWork2,[]) } Add(HubEx,9578769,469,147) { link(onEvent,7459882:doText,[]) }