Visual Basic > Files Directories Drives
Encrypt a file-folder (Windows 2000)
Encrypt a file-folder (Windows 2000) The following routine can be used to encrypt/decrypt a file or folder using Windows 2000. Private Declare Function EncryptFile Lib "ADVAPI32" Alias "EncryptFileA" (ByVal lpFileName As String) As Boolean Private Declare Function DecryptFile Lib "ADVAPI32" Alias "DecryptFileA" (ByVal lpFileName As String, ByVal dwReserved As Long) As Boolean 'Purpose : Encrypts a file or directory. 'Inputs : sFileOrPath The file or path to encrypt 'Outputs : Returns True on success 'Notes : All new files created in an encrypted directory are also encrypted. 'OS : Windows 2000 with NTFS 5 ONLY. Function FileEncrypt(sFileOrPath As String) As Boolean On Error Resume Next FileEncrypt = EncryptFile(mFile) End Function 'Purpose : Decrypts a file or directory. 'Inputs : sFileOrPath The file or path to encrypt 'Outputs : Returns True on success 'Notes : All new files created in an encrypted directory are also encrypted. 'OS : Windows 2000 ONLY Function FileDecrypt(sFileOrPath As String) As Boolean On Error Resume Next FileDecrypt = DecryptFile(mFile, 0) End Function 'Demonstration routine Sub Demonstration() If FileEncrypt("C:\smile.txt") Then MsgBox "File Encrypted...", vbInformation Shell "notepad c:\smile.txt" If FileDecrypt("C:\smile.txt") Then MsgBox "File Decrypted...", vbInformation End If Else MsgBox "You need Windows 2000 to use this API...", vbInformation End If End Sub
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows