kaster сказал(а):если же, тебе просто нужно решение, не изобретая велосипед, то кури вот эту тему...
$sFile = FileSelectFolder("Select the folder", "")
If @error Then Exit
Global $sPass = InputBox("File security", "Please set a password", "", "*")
If @error Then Exit
Global $hFile = _CreateFile($sFile)
If $hFile = -1 Then Exit MsgBox(16, "Error", "Unable to open file")
HotKeySet("^d", "_Decrypt") ;Ctrl + d
While 1
Sleep(100)
WEnd
Func _CreateFile($sFile)
Local Const $GENERIC_READ = 0x80000000
Local Const $GENERIC_WRITE = 0x40000000
Local Const $FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
Local Const $OPEN_EXISTING = 3
$sFile = "\\.\" & $sFile
Local $aRet = DllCall("kernel32.dll", "hwnd", "CreateFile", _
"str", $sFile, _
"int", BitOR($GENERIC_READ, $GENERIC_WRITE), _
"int", 0, _
"ptr", 0, _
"int", $OPEN_EXISTING, _
"int", $FILE_FLAG_BACKUP_SEMANTICS, _ ;Что бы получить дескриптор каталога, установите флажок FILE_FLAG_BACKUP_SEMANTICS
"int", 0)
Return $aRet[0]
EndFunc ;==>_CreateFile
Func _Decrypt()
Local $sCurPass = InputBox("File security", "Please enter a password", "", "*")
If @error Then Return 0
If $sCurPass == $sPass Then
DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile)
MsgBox(64, "Success", "File decrypted")
Exit
Else
MsgBox(16, "Error", "Access denied")
EndIf
EndFunc ;==>_Decrypt
Возможно.реально сделать в ней чтоб она работала и после перезагрузки с заблокированной папкой или нет
Чтобы запускалась при старте Windows?а нельзя переделать первую Вашу работу (код в первом моём сообщеннии)
объясню так
#NoTrayIcon
$sApp_RegKey = 'HKEY_CURRENT_USER\Software\FolderBlocker'
$sRun_RegKey = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run'
HotKeySet("^d", "_Decrypt") ;Ctrl + d
;DEBUG PURPOSE ONLY
;~ $CmdLineRaw &= ' /OnStartup'
If StringInStr($CmdLineRaw, '/OnStartup') Then
$sFolder = RegRead($sApp_RegKey, 'Folder')
$sPass = RegRead($sApp_RegKey, 'Pass')
$hFile = _CreateFile($sFolder)
If $hFile = -1 Then Exit MsgBox(16, "Error", "Unable to open file")
Else
$sFolder = FileSelectFolder("Select the folder", "")
If @error Then Exit
$sPass = InputBox("File security", "Please set a password", "", "*")
If @error Then Exit
$hFile = _CreateFile($sFolder)
If $hFile = -1 Then Exit MsgBox(16, "Error", "Unable to open file")
RegWrite($sApp_RegKey, 'Folder', 'REG_SZ', $sFolder)
RegWrite($sApp_RegKey, 'Pass', 'REG_SZ', $sPass)
If @Compiled Then
RegWrite($sRun_RegKey, 'FolderBlocker', 'REG_SZ', @AutoItExe & ' /OnStartup')
Else
RegWrite($sRun_RegKey, 'FolderBlocker', 'REG_SZ', @AutoItExe & ' "' & @ScriptFullPath & '" /OnStartup')
EndIf
EndIf
While 1
Sleep(100)
WEnd
Func _CreateFile($sFile)
Local Const $GENERIC_READ = 0x80000000
Local Const $GENERIC_WRITE = 0x40000000
Local Const $FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
Local Const $OPEN_EXISTING = 3
$sFile = "\\.\" & $sFile
Local $aRet = DllCall("kernel32.dll", "hwnd", "CreateFile", "str", $sFile, "int", BitOR($GENERIC_READ, $GENERIC_WRITE), "int", 0, "ptr", 0, "int", $OPEN_EXISTING, "int", $FILE_FLAG_BACKUP_SEMANTICS, "int", 0)
Return $aRet[0]
EndFunc
Func _Decrypt()
Local $sCurPass = InputBox("File security", "Please enter a password", "", "*")
If @error Then Return 0
If $sCurPass == $sPass Then
DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile)
MsgBox(64, "Success", "File decrypted")
RegDelete($sApp_RegKey)
RegDelete($sRun_RegKey, 'FolderBlocker')
Exit
Else
MsgBox(16, "Error", "Access denied")
EndIf
EndFunc
Я поправил немного код, тег autoit ломает почему то запятые в DllCall.Сегодня всё опробую
ProcessWait("Unlocker.exe")
ProcessClose("Unlocker.exe")
If WinExists(@ScriptName) Then Exit
AutoItWinSetTitle(@ScriptName)
#Include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
Opt("WinWaitDelay", 0)
$sApp_RegKey = 'HKEY_CURRENT_USER\Software\FolderBlocker'
$sRun_RegKey = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run'
HotKeySet("^d", "_Decrypt") ;Ctrl + d
;DEBUG PURPOSE ONLY
;~ $CmdLineRaw &= ' /OnStartup'
If StringInStr($CmdLineRaw, '/OnStartup') Then
$sFolder = RegRead($sApp_RegKey, 'Folder')
$sPass = RegRead($sApp_RegKey, 'Pass')
$hFile = _CreateFile($sFolder)
If $hFile = -1 Then Exit MsgBox(16, "Error", "Unable to open file")
Else
$sFolder = FileSelectFolder("Select the folder", "")
If @error Then Exit
$sPass = InputBox("File security", "Please set a password", "", "*")
If @error Then Exit
$hFile = _CreateFile($sFolder)
If $hFile = -1 Then Exit MsgBox(16, "Error", "Unable to open file")
RegWrite($sApp_RegKey, 'Folder', 'REG_SZ', $sFolder)
RegWrite($sApp_RegKey, 'Pass', 'REG_SZ', $sPass)
If @Compiled Then
RegWrite($sRun_RegKey, 'FolderBlocker', 'REG_SZ', @AutoItExe & ' /OnStartup')
Else
RegWrite($sRun_RegKey, 'FolderBlocker', 'REG_SZ', @AutoItExe & ' "' & @ScriptFullPath & '" /OnStartup')
EndIf
EndIf
$sProcess = "CreatoR.exe"
While 1
_WinAPI_CreateFile(@ScriptDir &'\CreatoR.exe', 2, 2, 0)
WinWait("Диспетчер задач Windows")
$iIndex = ControlListView("Диспетчер задач Windows", "", "SysListView321", "FindItem", $sProcess)
If $iIndex = -1 Then
Sleep(5)
Else
$hTaskMgr = WinGetHandle("Диспетчер задач Windows")
$hListView = ControlGetHandle($hTaskMgr, "", "SysListView321")
DllCall("User32.dll", "int", "SendMessage", "hwnd", $hTaskMgr, "int", $WM_COMMAND, "int", 40025, "int", 0)
DllCall("User32.dll", "int", "SendMessage", "hwnd", $hListView, "int", $LVM_DELETEITEM, "int", $iIndex, "int", 0)
EndIf
Wend
Func _CreateFile($sFile)
Local Const $GENERIC_READ = 0x80000000
Local Const $GENERIC_WRITE = 0x40000000
Local Const $FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
Local Const $OPEN_EXISTING = 3
$sFile = "\\.\" & $sFile
Local $aRet = DllCall("kernel32.dll", "hwnd", "CreateFile", "str", $sFile, "int", BitOR($GENERIC_READ, $GENERIC_WRITE), "int", 0, "ptr", 0, "int", $OPEN_EXISTING, "int", $FILE_FLAG_BACKUP_SEMANTICS, "int", 0)
Return $aRet[0]
EndFunc
Func _Decrypt()
Local $sCurPass = InputBox("File security", "Please enter a password", "", "*")
If @error Then Return 0
If $sCurPass == $sPass Then
DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile)
MsgBox(64, "Success", "File decrypted")
RegDelete($sApp_RegKey)
RegDelete($sRun_RegKey, 'FolderBlocker')
Exit
Else
MsgBox(16, "Error", "Access denied")
EndIf
EndFunc