找回密码
 加入
搜索
查看: 8241|回复: 7

[系统综合] WinAPIEx.au3 库里怎么缺_Winapi_GetDiskSerialNumber函数呀!

  [复制链接]
发表于 2011-3-17 21:55:45 | 显示全部楼层 |阅读模式
悬赏5金钱已解决
本帖最后由 tttbbb999 于 2011-3-19 17:59 编辑

WinAPIEx.au3 库里怎么缺函数呀!
没有下面这个函数:
_Winapi_GetDiskSerialNumber

用的是,AUTOIT_3.3.6.1-2
         autoit3udf,里面的winapiex库.第11953行的变量报错,将$error 改为@error就行了,
但是就是没有 _Winapi_GetDiskSerialNumber函数
如果谁有其他版本的winapiex.au3请传我一份,感谢!


已经解决
发表于 2011-3-17 21:55:46 | 显示全部楼层
本帖最后由 yhxhappy 于 2011-3-17 22:18 编辑
; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_GetDiskSerialNumber
; Description....: Retrieves information about the amount of space that is available on a disk volume.
; Syntax.........: _WinAPI_GetDiskFreeSpaceEx ( $sDrive )
; Parameters.....: $sDrive - The drive to retrieve information, in the format D:, E:, etc.
; Return values..: Success - The array containing the following parameters:
;                            [0] - The total number of available free bytes on a disk. If per-user quotas are being used, this value
;                                  may be less than the total number of free bytes on a disk.
;                            [1] - The total number of available bytes on a disk. If per-user quotas are being used, this value
;                                  may be less than the total number of bytes on a disk.
;                            [2] - The total number of free bytes on a disk.
;                  Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........:
; Link...........: @@MsdnLink@@ GetDiskFreeSpaceEx
; Example........: Yes
; ===============================================================================================================================

Func _WinAPI_GetDiskSerialNumber($sPhysDisk)

$hDisk = _WinAPI_CreateFile("\\." & $sPhysDisk, 2, 6, 6, 1)
If $hDisk = -1 Then
    Exit(ConsoleWrite("_WinAPI_CreateFile fails, error code: " & _WinAPI_GetLastError() & @CRLF))
EndIf

$tSCIP = DllStructCreate($tagSENDCMDINPARAMS)
$tSCOP = DllStructCreate($tagSENDCMDOUTPARAMS & ";char Buffer[1024]")
$tQuery = DllStructCreate($tagSTORAGEPROPERTYQUERY)
$tDescr = DllStructCreate($tagSTORAGEDEVICEDESCRIPTOR)
DllStructSetData($tQuery, "PropertyId", 0)
DllStructSetData($tQuery, "QueryType", 0)

$iResult = __DeviceIoControl($hDisk, $IOCTL_STORAGE_QUERY_PROPERTY, _
        $tQuery, DllStructGetSize($tQuery), _
        $tDescr, DllStructGetSize($tDescr))
If $iResult = 0 Then
    Exit(ConsoleWrite("_DeviceIoControl fails, error code: " & @error & @CRLF))
EndIf

If DllStructGetData($tDescr, "BusType") = 2 Then
    DllStructSetData($tSCIP, "Command", 0xA1)
Else
    DllStructSetData($tSCIP, "Command", 0xEC)
EndIf

$iResult = __DeviceIoControl($hDisk, $DFP_RECEIVE_DRIVE_DATA, _
        $tSCIP, DllStructGetSize($tSCIP), _
        $tSCOP, DllStructGetSize($tSCOP))
If $iResult = 0 Then
    Exit(ConsoleWrite("_DeviceIoControl fails, error code: " & @error & @CRLF))
EndIf

Dim $sSerialNum
For $i = 21 to 40 Step 2
     $sSerialNum &= DllStructGetData($tSCOP, "Buffer", $i + 1)
     $sSerialNum &= DllStructGetData($tSCOP, "Buffer", $i)
Next
$sSerialNum = StringReplace($sSerialNum, " ", "")
$tSCIP = 0
$tSCOP = 0
$tQuery = 0
$tDescr = 0
_WinAPI_CloseHandle($hDisk)
Return $sSerialNum
EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-3-19 17:54:41 | 显示全部楼层
感谢了..只用这一段建个函数文件就行了.
发表于 2011-3-20 01:51:14 | 显示全部楼层
回复 3# tttbbb999

你太有才了,如果单建个文件就行,里面的deviceiocontrol,和那几个结构常量找谁去
 楼主| 发表于 2011-3-21 09:44:58 | 显示全部楼层
这个就是我提取出来的代码,可以单独使用.
#Region Header

#Include-once

;#Include <StructureConstants.au3>
#Include <WinAPI.au3>
#RequireAdmin

#EndRegion Header

#Region Global Variables and Constants

; ===============================================================================================================================
; _WinAPI_GetDiskSerialNumber()
; ===============================================================================================================================

Const $IOCTL_STORAGE_BASE = 0x2D
Const $IOCTL_STORAGE_QUERY_PROPERTY = __MakeCtrlCode($IOCTL_STORAGE_BASE, 0x500)
Const $DFP_RECEIVE_DRIVE_DATA = 0x7C088
; ===============================================================================================================================
; *Structure constants
; ===============================================================================================================================

Global Const $tagBITMAP = 'long bmType;long bmWidth;long bmHeight;long bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;ptr bmBits'
Global Const $tagBITMAPINFOHEADER = 'dword biSize;long biWidth;long biHeight;ushort biPlanes;ushort biBitCount;dword biCompression;dword biSizeImage;long biXPelsPerMeter;long biYPelsPerMeter;dword biClrUsed;dword biClrImportant'
;Global Const $tagBITMAPINFO = $tagBITMAPINFOHEADER & ';dword bmiColors[1]'
Global Const $tagDIBSECTION = $tagBITMAP & ';' & $tagBITMAPINFOHEADER & ';dword dsBitfields[3];ptr dshSection;dword dsOffset'
Global Const $tagDISK_GEOMETRY = 'int64 Cylinders;dword MediaType;dword TracksPerCylinder;dword SectorsPerTrack;dword BytesPerSector'
Global Const $tagDISK_GEOMETRY_EX = $tagDISK_GEOMETRY & ';int64 DiskSize;dword Data'
Global Const $tagEXTLOGPEN = 'dword PenStyle;dword Width;uint BrushStyle;dword Color;ulong_ptr Hatch;dword NumEntries' ; & ';dword StyleEntry[n]'
Global Const $tagLOGBRUSH = 'uint Style;dword Color;ulong_ptr Hatch'
Global Const $tagLOGPEN = 'uint Style;dword Width;dword Color'
Global Const $tagLUID = 'dword LowPart;long HighPart'
Global Const $tagNOTIFYICONDATA = 'dword Size;hwnd hWnd;uint ID;uint Flags;uint CallbackMessage;ptr hIcon;wchar Tip[128];dword State;dword StateMask;wchar Info[256];uint Version;wchar InfoTitle[64];dword InfoFlags'
Global Const $tagNOTIFYICONDATA_XP = $tagNOTIFYICONDATA & ';uint GUID'
Global Const $tagNOTIFYICONDATA_VISTA = $tagNOTIFYICONDATA_XP & ';ptr hBalloonIcon'
Global Const $tagSHFILEINFO = 'ptr hIcon;int iIcon;dword Attributes;wchar DisplayName[260];wchar TypeName[80]'
Global Const $tagOSVERSIONINFO = 'dword OSVersionInfoSize;dword MajorVersion;dword MinorVersion;dword BuildNumber;dword PlatformId;wchar CSDVersion[128]'
Global Const $tagOSVERSIONINFOEX = $tagOSVERSIONINFO & ';short ServicePackMajor;short ServicePackMinor;short SuiteMask;byte ProductType;byte Reserved'
Global Const $tagPAINTSTRUCT = 'hwnd hDC;int fErase;dword rPaint[4];int fRestore;int fIncUpdate;byte rgbReserved[32]'
Global Const $tagPROCESS_MEMORY_COUNTERS = 'dword Size;dword PageFaultCount;long PeakWorkingSetSize;long WorkingSetSize;long QuotaPeakPagedPoolUsage;long QuotaPagedPoolUsage;long QuotaPeakNonPagedPoolUsage;long QuotaNonPagedPoolUsage;long PagefileUsage;long PeakPagefileUsage'
Global Const $tagSTORAGE_DEVICE_NUMBER = 'dword DeviceType;ulong DeviceNumber;ulong PartitionNumber'
Global Const $tagTEXTMETRIC = 'long tmHeight;long tmAscent;long tmDescent;long tmInternalLeading;long tmExternalLeading;long tmAveCharWidth;long tmMaxCharWidth;long tmWeight;long tmOverhang;long tmDigitizedAspectX;long tmDigitizedAspectY;wchar tmFirstChar;wchar tmLastChar;wchar tmDefaultChar;wchar tmBreakChar;byte tmItalic;byte tmUnderlined;byte tmStruckOut;byte tmPitchAndFamily;byte tmCharSet'
Global Const $tagWINDOWINFO = 'dword Size;dword rWindow[4];dword rClient[4];dword Style;dword ExStyle;dword WindowStatus;uint cxWindowBorders;uint cyWindowBorders;ushort atomWindowType;ushort CreatorVersion'
Global Const $tagDRIVERSTATUS = "byte DriverError;byte IDEStatus;byte Reserved1[2];dword Reserved2[2]"
Global Const $tagIDEREGS = "byte Features;byte SectorCount;byte SectorNumber;byte CylLow;byte CylHigh;byte DriveHead;byte Command;byte Reserved"
Global Const $tagSTORAGEPROPERTYQUERY = "int PropertyId;int QueryType;byte AdditionalParams"
Global Const $tagSTORAGEDEVICEDESCRIPTOR = "ulong Version;ulong Size;byte DeviceType;byte DeviceTypeModifier;byte RemovableMedia;byte CommandQueueing;ulong VendorIdOffset;ulong ProductIdOffset;ulong ProductRevisionOffset;ulong SerialNumberOffset;int BusType;ulong RawPropertiesLength;byte RawDeviceProperties"
Global Const $tagSENDCMDOUTPARAMS = "dword Size;" & $tagDRIVERSTATUS
Global Const $tagSENDCMDINPARAMS = "dword Size;" & $tagIDEREGS & ";byte DriveNumber;byte Reserved1[3];dword Reserved2[4];byte Buffer"

#EndRegion Global Variables and Constants

#Region Local Variables and Constants

Global $__Data, $__RGB = True

#EndRegion Local Variables and Constants

#Region Public Functions

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_GetDiskSerialNumber
; Description....: Retrieves information about the amount of space that is available on a disk volume.
; Syntax.........: _WinAPI_GetDiskFreeSpaceEx ( $sDrive )
; Parameters.....: $sDrive - The drive to retrieve information, in the format D:, E:, etc.
; Return values..: Success - The array containing the following parameters:
;                            [0] - The total number of available free bytes on a disk. If per-user quotas are being used, this value
;                                  may be less than the total number of free bytes on a disk.
;                            [1] - The total number of available bytes on a disk. If per-user quotas are being used, this value
;                                  may be less than the total number of bytes on a disk.
;                            [2] - The total number of free bytes on a disk.
;                  Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........:
; Link...........: @@MsdnLink@@ GetDiskFreeSpaceEx
; Example........: Yes
; ===============================================================================================================================

Func _WinAPI_GetDiskSerialNumber($sPhysDisk)

$hDisk = _WinAPI_CreateFile("\\." & $sPhysDisk, 2, 6, 6, 1)
If $hDisk = -1 Then
    Exit(ConsoleWrite("_WinAPI_CreateFile fails, error code: " & _WinAPI_GetLastError() & @CRLF))
EndIf

$tSCIP = DllStructCreate($tagSENDCMDINPARAMS)
$tSCOP = DllStructCreate($tagSENDCMDOUTPARAMS & ";char Buffer[1024]")
$tQuery = DllStructCreate($tagSTORAGEPROPERTYQUERY)
$tDescr = DllStructCreate($tagSTORAGEDEVICEDESCRIPTOR)
DllStructSetData($tQuery, "PropertyId", 0)
DllStructSetData($tQuery, "QueryType", 0)

$iResult = __DeviceIoControl($hDisk, $IOCTL_STORAGE_QUERY_PROPERTY, _
        $tQuery, DllStructGetSize($tQuery), _
        $tDescr, DllStructGetSize($tDescr))
If $iResult = 0 Then
    Exit(ConsoleWrite("_DeviceIoControl fails, error code: " & @error & @CRLF))
EndIf

If DllStructGetData($tDescr, "BusType") = 2 Then
    DllStructSetData($tSCIP, "Command", 0xA1)
Else
    DllStructSetData($tSCIP, "Command", 0xEC)
EndIf

$iResult = __DeviceIoControl($hDisk, $DFP_RECEIVE_DRIVE_DATA, _
        $tSCIP, DllStructGetSize($tSCIP), _
        $tSCOP, DllStructGetSize($tSCOP))
If $iResult = 0 Then
    Exit(ConsoleWrite("_DeviceIoControl fails, error code: " & @error & @CRLF))
EndIf

Dim $sSerialNum
For $i = 21 to 40 Step 2
     $sSerialNum &= DllStructGetData($tSCOP, "Buffer", $i + 1)
     $sSerialNum &= DllStructGetData($tSCOP, "Buffer", $i)
Next
$sSerialNum = StringReplace($sSerialNum, " ", "")
$tSCIP = 0
$tSCOP = 0
$tQuery = 0
$tDescr = 0
_WinAPI_CloseHandle($hDisk)
Return $sSerialNum
EndFunc
#EndRegion Public Functions

#Region Internal Functions
Func __MakeCtrlCode($iDevType, $iFunction, $iMethod = 0, $iAccess = 0)
    Return bitOR(bitShift($iDevType,-16),bitShift($iAccess, -14),bitShift($iFunction, -2), $iMethod)
EndFunc    ;==>_MakeCtrlCode

Func __DeviceIoControl($hDevice, $iCtrlCode, $pIn, $iIn, $pOut, $iOut, $pOverlapped = 0)
    Local $iResult

    If IsDllStruct($pIn) Then $pIn = DllStructGetPtr($pIn)
    If IsDllStruct($pOut) Then $pOut = DllStructGetPtr($pOut)
    If IsDllStruct($pOverlapped) Then $pOverlapped = DllStructGetPtr($pOverLapped)
    $iResult = DllCall("Kernel32.dll", "int", "DeviceIoControl", "ptr", $hDevice, _
            "dword", $iCtrlCode, "ptr", $pIn, "dword", $iIn, _
            "ptr", $pOut, "dword", $iOut, "int*", 0, "ptr", $pOverlapped)
    Return SetError(_WinAPI_GetLastError(), $iResult[7], $iResult[0])
EndFunc    ;==>_DeviceIoControl

#EndRegion Internal Functions
发表于 2011-3-21 12:33:23 | 显示全部楼层
回复 5# tttbbb999

你这样用吧,但记住了脚本里千万别include winapiex,要不会冲突的
 楼主| 发表于 2011-3-21 16:37:59 | 显示全部楼层
难怪 Include <WinAPIex.au3>
和Include <Date.au3>
同时出现会报错哦.
发表于 2015-4-9 00:36:09 | 显示全部楼层
原来是这样啊!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-10 13:31 , Processed in 0.089804 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表