Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Encryptfile (advapi32)
 
.
Summary
EncryptFile turns on file level system encryption for a specific file or folder
Summary
EncryptFile turns on file level system encryption for a specific file

C# Signature:

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EncryptFile(string filename);

VB Signature:

Declare Function EncryptFile Lib "advapi32.dll" (TODO) As TODO

User-Defined Types:

None.

Notes:

This requires that Windows supports Encrypted File System (EFS) which is only

supported under NTFS.

Tips & Tricks:

Please add some!

C# Sample Code:

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EncryptFile(string filename);

string FileName = "C:\PATH\TO\YOUR\FILE";
if(EncryptFile(FileName)){
   //File encrypted
} else{
   throw new Exception("Encryption failed.");
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
Encryptfile on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions