我试图在QB64中使用此程序加密文件。
它实际上并不加密文件,并且总是返回成功。为什么?
DECLARE LIBRARY
FUNCTION EncryptFile (f$)
FUNCTION DecryptFile (f$, BYVAL f&)
END DECLARE
PRINT "Enter filename";
INPUT f$
IF f$ <> "" THEN
f$ = f$ + CHR$(0)
x = EncryptFile(f$)
IF x = 0 THEN
PRINT "Error encrypting file."
ELSE
PRINT "File encrypted."
END IF
END IF
END
解决方案是检测文件名的加密状态,如:
REM checks encryption status of a filename
DECLARE DYNAMIC LIBRARY "advapi32"
FUNCTION FileEncryptionStatusA% (f$, f&)
END DECLARE
DO
PRINT "Filename";
INPUT f$
IF f$ = "" THEN END
x = FileEncryptionStatusA(f$, f&)
IF x = 0 THEN
PRINT "Error accessing file."
END IF
IF x THEN
SELECT CASE f&
CASE 0
PRINT "File can be encrypted."
CASE 1
PRINT "File is encrypted."
CASE 2
PRINT "File is system."
CASE 3
PRINT "File is root."
CASE 4
PRINT "File is system directory."
CASE 5
PRINT "Encryption status unknown."
CASE 6
PRINT "File system does not support encryption."
CASE 7 ' reserved
CASE 8
PRINT "File is read-only."
END SELECT
END IF
LOOP
END