Decrypts an encrypted file or directory
#include <WinAPIFiles.au3>
_WinAPI_DecryptFile ( $sFilePath )
$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. |
Success: | True. |
Failure: | False, call _WinAPI_GetLastError() to get extended error information |
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.
Search DecryptFile in MSDN Library.
#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