VB and VBA Users Source Code: Encrypt a file/folder (Windows 2000)
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Encrypt a file/folder (Windows 2000)
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Friday, February 23, 2001
Hits:
4574
Category:
Windows API
Article:
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 'Author : Andrew Baker 'Date : 31/12/2000 13:51 'Notes : All new files created in an encrypted directory are also encrypted. 'OS : Windows 2000 with NTFS 5 ONLY. 'Revisions : 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 'Author : Andrew Baker 'Date : 31/12/2000 13:51 'Notes : All new files created in an encrypted directory are also encrypted. 'OS : Windows 2000 ONLY 'Revisions : 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
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder