由于 windows 不为单个文件夹提供密码保护,因此有许多第三方软件,如“文件夹锁定”,可以完成这项工作。我想知道这类应用程序背后的逻辑,并找到了一个类似这样的代码:'lock-a-folder'。这是我不熟悉的 AutoIt 脚本。但是,我只想知道这里使用的逻辑。
这些是我感兴趣的脚本的主要功能:
Func Lock($slected)
Local $Temp,$TempFile
If @error or $slected = "" Then Return("Empty selection/Cancel Pressed")
If Not FileExists($slected) Then
MsgBox(0, $AppName, $slected & " " & Lang('doesntexist'), 0, $WIN1)
Return('doesntexist')
EndIf
Local $l0ckd = RegRead("HKEY_CURRENT_USER\SOFTWARE\" & $AppName, "lockedfolders")
_DebugOut('RegRead("HKEY_CURRENT_USER\SOFTWARE\" & $AppName, "lockedfolders") = ' & $l0ckd)
If Not StringInStr($l0ckd, $slected & ".{90F8C996-7C70-4331-9D70-FB357D559FD5}|") = 0 Then
MsgBox(0, $AppName, $slected & " " & Lang('alreadyinlist'), 0, $WIN1)
Return('alreadyinlist')
EndIf
If $CmdLine[0] = 0 Then
GUICtrlSetData($List1, "")
GUICtrlSetData($List1, Lang('plzwait') & "....")
GUISetState(@SW_DISABLE)
EndIf
_DebugOut($slected)
If $CmdLine[0] = 0 Then GUISetState(@SW_ENABLE)
If DirMove($slected, $slected & ".{90F8C996-7C70-4331-9D70-FB357D559FD5}") = 0 Then
FileSetAttrib($slected, "-RSH")
MsgBox(0, $AppName, $slected & " " & Lang('unable2lock'), 0, $WIN1)
If $CmdLine[0] = 0 Then Readfolders()
Return('unable2lock')
EndIf
$slected = $slected & ".{90F8C996-7C70-4331-9D70-FB357D559FD5}"
FileSetAttrib($slected, "+RSH")
$l0ckd &= $slected & "|"
_DebugOut("$l0ckd &= $slected| = " & $l0ckd)
$debug = RegWrite("HKEY_CURRENT_USER\SOFTWARE\" & $AppName, "lockedfolders", "REG_SZ", $l0ckd)
_DebugOut('RegWrite("HKEY_CURRENT_USER\SOFTWARE\" & $AppName, "lockedfolders", "REG_SZ", $l0ckd) = ' & $debug)
If $CmdLine[0] = 0 Then Readfolders()
Return("Done")
EndFunc ;==>Lock
Func UnLock($slected)
_DebugOut($slected)
If $slected = "" Or @error Then
MsgBox(0, $AppName, Lang('selectfirst'), 0, $WIN1)
Return("Empty selection/Cancel Pressed")
EndIf
If $CmdLine[0] = 0 Then
GUICtrlSetData($List1, "")
GUICtrlSetData($List1, Lang('plzwait') & "....")
GUISetState(@SW_DISABLE)
EndIf
Local $Temp = StringReplace($slected, ".{90F8C996-7C70-4331-9D70-FB357D559FD5}", "", 0, 2)
_DebugOut("$Temp = " & $Temp)
FileSetAttrib($slected, "-RSH")
Local $Temp1
$Temp1 = DirMove($slected, $Temp)
If $CmdLine[0] = 0 Then GUISetState(@SW_ENABLE)
If $Temp1 = 0 Then
$Temp1 = DirMove($slected, $Temp & ".recovered")
EndIf
If $Temp1 = 0 Then
MsgBox(0, $AppName, $slected & " " & Lang('unable2unlock'), 0, $WIN1)
If $CmdLine[0] = 0 Then Readfolders()
Return('unable2unlock')
EndIf
Local $l0ckd = RegRead("HKEY_CURRENT_USER\SOFTWARE\" & $AppName, "lockedfolders")
_DebugOut('RegRead("HKEY_CURRENT_USER\SOFTWARE\" & $AppName, "lockedfolders") = ' & $l0ckd)
$Temp = StringReplace($l0ckd, $slected & "|", "")
_DebugOut('StringReplace($l0ckd, $slected & "|", "")' & " = " & $Temp)
$debug = RegWrite("HKEY_CURRENT_USER\SOFTWARE\" & $AppName, "lockedfolders", "REG_SZ", $Temp)
_DebugOut('RegWrite("HKEY_CURRENT_USER\SOFTWARE\" & $AppName, "lockedfolders", "REG_SZ", $l0ckd) = ' & $debug)
If $CmdLine[0] = 0 Then Readfolders()
Return("Done")
EndFunc ;==>UnLock
谁能告诉我逻辑?