Skip to content

Latest commit

 

History

History
83 lines (62 loc) · 2.2 KB

sample_540.md

File metadata and controls

83 lines (62 loc) · 2.2 KB

Home

Copying files as a transacted operation (Vista)

Before you begin:

Windows Vista offers transaction protection for various file operations: create, delete, copy, move and more.

See also:


Code:

#DEFINE INVALID_HANDLE_VALUE -1
#DEFINE COPY_FILE_FAIL_IF_EXISTS 0x00000001
#DEFINE COPY_FILE_OPEN_SOURCE_FOR_WRITE 0x00000004

DO declare

LOCAL hTrans
hTrans = CreateTransaction(0, 0, 0, 0, 0, 1000, NULL)
IF hTrans = INVALID_HANDLE_VALUE
	? "CreateTransaction call failed:", GetLastError()
	RETURN
ENDIF

LOCAL cSrc, cDst, nResult
cSrc = "c:\temp\test.txt"
cDst = "c:\temp\test1.txt"

nResult = CopyFileTransacted(cSrc, cDst, 0, 0, 0,;
	BITOR(COPY_FILE_FAIL_IF_EXISTS,;
	COPY_FILE_OPEN_SOURCE_FOR_WRITE),;
	hTrans)
	
IF nResult = 0
	? "CopyFileTransacted call failed:", GetLastError()
	= RollbackTransaction(m.hTrans)
ELSE
	= CommitTransaction(m.hTrans)
ENDIF

= CloseHandle(hTrans)
* end of main

PROCEDURE declare
	DECLARE INTEGER CopyFileTransacted IN kernel32;
		STRING lpExistingFileName, STRING lpNewFileName,;
		INTEGER lpProgressRoutine, INTEGER lpData,;
		INTEGER pbCancel, INTEGER dwCopyFlags,;
		INTEGER hTransaction

	DECLARE INTEGER CloseHandle IN kernel32;
		INTEGER hObject

	DECLARE INTEGER CommitTransaction IN KtmW32;
		INTEGER TransactionHandle

	DECLARE INTEGER RollbackTransaction IN KtmW32;
		INTEGER TransactionHandle

	DECLARE INTEGER GetLastError IN kernel32

	DECLARE INTEGER CreateTransaction IN KtmW32;
		INTEGER lpTransactionAttributes, INTEGER UOW,;
		INTEGER CreateOptions, INTEGER IsolationLevel,;
		INTEGER IsolationFlags, INTEGER Timeout,;
		STRING @Description  

Listed functions:

CloseHandle
CommitTransaction
CopyFileTransacted
CreateTransaction
GetLastError
RollbackTransaction