Function Reference


_WinAPI_DecryptFile

Decrypts an encrypted file or directory

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

Parameters

$sFilePath The name of the file or directory to be decrypted. If $sFilePath specifies a read-only file, the function fails and the last error code is ERROR_FILE_READ_ONLY (6009). If $sFilePath specifies a directory that contains a read-only file, the functions succeeds but the directory is not decrypted.

Return Value

Success: True.
Failure: False, call _WinAPI_GetLastError() to get extended error information

Remarks

The _WinAPI_DecryptFile() function requires exclusive access to the file being decrypted, and will fail if another process is using the file.

If the file is not encrypted, the function simply returns a nonzero value, which indicates success.

See Also

Search DecryptFile in MSDN Library.

Example

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

Local $sFile = FileOpenDialog('Select File', @ScriptDir, 'All Files (*.*)', BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST))
If @error Then Exit

Switch _WinAPI_FileEncryptionStatus($sFile)
        Case $FILE_ENCRYPTABLE
                If _WinAPI_EncryptFile($sFile) Then
                        MsgBox(($MB_ICONINFORMATION + $MB_SYSTEMMODAL), 'Encryption File', 'The file encrypted is successfully.')
                Else
                        MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Encryption File', 'Unable to encrypt file.')
                EndIf
        Case $FILE_IS_ENCRYPTED
                If MsgBox(($MB_YESNO + $MB_ICONQUESTION + $MB_SYSTEMMODAL), 'Encryption File', 'The file is already encrypted.' & @CRLF & @CRLF & 'Decrypt?') = 6 Then
                        If _WinAPI_DecryptFile($sFile) Then
                                MsgBox(($MB_ICONINFORMATION + $MB_SYSTEMMODAL), 'Encryption File', 'The file decrypted is successfully.')
                        Else
                                MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Encryption File', 'Unable to decrypt file.')
                        EndIf
                EndIf
        Case Else
                MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Encryption File', 'Unable to perform operation.')
EndSwitch