Function Reference


Opens the file that matches the specified object identifier

#include <WinAPIFiles.au3>
_WinAPI_OpenFileById ( $hFile, $vID [, $iAccess = 0 [, $iShare = 0 [, $iFlags = 0]]] )


$hFile The path or handle to any file on a volume or share on which the file to be opened is stored.
$vID 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 [optional] The access to the object. Access can be read, write, or both. If this parameter is 0 (Default), the
application can query file and device attributes without accessing a device.
(See MSDN for more information)
$iShare [optional] The sharing mode of an object, which can be read, write, both, or none. If this parameter is 0 (Default) and
function succeeds, the object cannot be shared and cannot be opened again until the handle is closed.
$iFlags [optional] 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.

Return Value

Success: Handle to a specified file.
Failure: 0 and sets the @error flag to non-zero, call _WinAPI_GetLastError() to get extended error information.


When an application is finished using the object handle returned by this function, use the _WinAPI_CloseHandle()
function to close the handle. This not only frees up system resources, but can have wider influence on things
like sharing the file or device and committing data to disk.

This function requires Windows Vista or later.



See Also

Search OpenFileById in MSDN Library.


#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <WinAPISys.au3>

If _WinAPI_GetVersion() < '6.0' Then
    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', 'Require Windows Vista or later.')

; Create temporary file
Local $sFile = _WinAPI_GetTempFileName(@TempDir)

; Create unique object ID for a file
Local $tGUID = _WinAPI_CreateObjectID($sFile)

ConsoleWrite('GUID: ' & _WinAPI_StringFromGUID($tGUID) & @CRLF)

; Open file by object ID and retrieve its full path
Local $hFile = _WinAPI_OpenFileById(_WinAPI_PathStripToRoot(@TempDir), $tGUID, 0, BitOR($FILE_SHARE_DELETE, $FILE_SHARE_READ, $FILE_SHARE_WRITE))
$sFile = _WinAPI_GetFinalPathNameByHandleEx($hFile)

ConsoleWrite('Path: ' & StringRegExpReplace($sFile, '\\+.\\', '') & @CRLF)

; Delete file