EncryptFile

[This is preliminary documentation and subject to change.]

The EncryptFile function encrypts a file or directory. All data streams in a file are encrypted. All new files created in an encrypted directory are encrypted.

BOOL EncryptFile(
  LPCTSTR lpFileName
);
 

Parameters

lpFileName
Pointer to a null-terminated string that specifies the name of the file or directory to encrypt.

The caller must have FILE_READ_DATA, FILE_WRITE_DATA, FILE_READ_ATTRIBUTES, FILE_WRITE_ATTRIBUTES, and SYNCHRONIZE access to the file.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The EncryptFile function requires exclusive access to the file being encrypted, and will fail another process is using the file.

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

To decrypt an encrypted file, use the DecryptFile function.

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also

File Systems Overview, File System Functions, DecryptFile