Opens the file that matches the specified object identifier.
#Include <WinAPIEx.au3>
_WinAPI_OpenFileById ( $hFile, $ID [, $iAccess [, $iShare [, $iFlags]]] )
$hFile | The path or handle to any file on a volume or share on which the file to be opened is stored. |
$ID | The file identifier (FileID), or $tagGUID structure (ObjectID), or GUID's string representation in the form "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" that identifies the file to open. |
$iAccess | [可选参数] The access to the object. Access can be read, write, or both. If this parameter is 0, the application can query file and device attributes without accessing a device. $GENERIC_READ $GENERIC_WRITE (查看MSDN得到更多信息) |
$iShare | [可选参数] The sharing mode of an object, which can be read, write, both, or none. If this parameter is 0 and function succeeds, the object cannot be shared and cannot be opened again until the handle is closed. $FILE_SHARE_DELETE $FILE_SHARE_READ $FILE_SHARE_WRITE |
$iFlags | [可选参数] The file flags. When _WinAPI_OpenFileById() opens a file, it combines the file flags with existing file attributes, and ignores any supplied file attributes. This parameter can include any combination of the following values. $FILE_FLAG_BACKUP_SEMANTICS $FILE_FLAG_NO_BUFFERING $FILE_FLAG_OPEN_NO_RECALL $FILE_FLAG_OPEN_REPARSE_POINT $FILE_FLAG_OVERLAPPED $FILE_FLAG_RANDOM_ACCESS $FILE_FLAG_SEQUENTIAL_SCAN $FILE_FLAG_WRITE_THROUGH |
Success | Handle to a specified file. |
失败: | 返回 0 并设置 @error 标志为非 0 值. |
在MSDN中搜索
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
If _WinAPI_GetVersion() < '6.0' Then
MsgBox(16, 'Error', 'Require Windows Vista or later.')
Exit
EndIf
Global $tGUID, $sFile, $hFile
; Create temporary file
$sFile = _WinAPI_GetTempFileName(@TempDir)
; Create unique object ID for a file
$tGUID = _WinAPI_CreateObjectID($sFile)
ConsoleWrite('GUID: ' & _WinAPI_StringFromGUID(DllStructGetPtr($tGUID)) & @CR)
; Open file by object ID and retrieve its full path
$hFile = _WinAPI_OpenFileById(_WinAPI_PathStripToRoot(@TempDir), $tGUID, 0, BitOR($FILE_SHARE_DELETE, $FILE_SHARE_READ, $FILE_SHARE_WRITE))
$sFile = _WinAPI_GetFinalPathNameByHandleEx($hFile)
_WinAPI_CloseHandle($hFile)
ConsoleWrite('Path: ' & StringRegExpReplace($sFile, '\\+.\\', '') & @CR)
; Delete file
FileDelete($sFile)