Function Reference


_WinAPI_CreateObjectID

Creates or retrieves the object identifier for the specified file or directory

#include <WinAPIFiles.au3>
_WinAPI_CreateObjectID ( $sFilePath )

Parameters

$sFilePath Path to the file or directory to create or retrieve object identifier.

Return Value

Success: $tagGUID structure that contains the object identifier for the file or directory within the volume on which it resides.
Failure: Sets the @error flag to non-zero.

Remarks

If the object identifier of a file or directory does not already have one, the _WinAPI_CreateObjectID() creates it.
If the object identifier already exists, the function just returns it.

See Also

Search FSCTL_CREATE_OR_GET_OBJECT_ID in MSDN Library.

Example

#include <MsgBoxConstants.au3>
#include <WinAPIConv.au3>
#include <WinAPIFiles.au3>
#include <WinAPIHObj.au3>
#include <WinAPIShPath.au3>
#include <WinAPISys.au3>

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

; 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)
_WinAPI_CloseHandle($hFile)

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

; Delete file
FileDelete($sFile)