函数参考


_WinAPI_CreateObjectID

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

#Include <WinAPIEx.au3>
_WinAPI_CreateObjectID ( $sPath )

参数

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

返回值

Success $tagGUID structure that contains the object identifier for the file or directory within the volume on which it resides.
失败: 返回 0 并设置 @error 标志为非 0 值.

注意/说明

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.

相关

详情参考

在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)