函数参考


_WinAPI_EncryptFile

Encrypts a file or directory.

#Include <WinAPIEx.au3>
_WinAPI_EncryptFile ( $sFile )

参数

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

返回值

成功: 返回 1.
失败: 返回 0 并设置 @error 标志为非 0 值.

注意/说明

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

If the file is already encrypted, the function simply returns a nonzero value, which indicates success.
If the file is compressed, the function will decompress the file before encrypting it.

To decrypt an encrypted file, use the _WinAPI_DecryptFile() function.

相关

详情参考

在MSDN中搜索


示例/演示


#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $File = FileOpenDialog('Select File', @ScriptDir, 'All Files (*.*)', 1 + 2)

If Not $File Then
    Exit
EndIf

Switch _WinAPI_FileEncryptionStatus($File)
    Case $FILE_ENCRYPTABLE
        If _WinAPI_EncryptFile($File) Then
            MsgBox(64, 'Encryption File', 'The file encrypted is successfully.')
        Else
            MsgBox(16, 'Encryption File', 'Unable to encrypt file.')
        EndIf
    Case $FILE_IS_ENCRYPTED
        If MsgBox(36, 'Encryption File', 'The file is already encrypted.' & @CR & @CR & 'Decrypt?') = 6 Then
            If _WinAPI_DecryptFile($File) Then
                MsgBox(64, 'Encryption File', 'The file decrypted is successfully.')
            Else
                MsgBox(16, 'Encryption File', 'Unable to decrypt file.')
            EndIf
        EndIf
    Case Else
        MsgBox(16, 'Encryption File', 'Unable to perform operation.')
EndSwitch