[Solved] Lock a folder? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

[Solved] Lock a folder?

26 Aug 2017, 18:07

Hey all,

Is it possible to lock a folder in the way you can lock a file to prevent deletion/moving by another user?
file := FileOpen(FileName, "r-d")

is this possible with the LockFile function or any other way? Edit: CreateFile?
help appreciated
thanks

Solved by Flipeador below
Last edited by gwarble on 28 Aug 2017, 09:32, edited 1 time in total.
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Lock a folder?

27 Aug 2017, 02:08

Probably a workaround: http://www.makeuseof.com/tag/how-to-loc ... -computer/
Run/FileSetAttrib/RegWrite/...
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Lock a folder?

27 Aug 2017, 09:04

Code: Select all

DirName := A_Desktop . "\1"
R := DllCall("Kernel32.dll\CreateFileW", "Ptr", &DirName, "UInt", 2, "UInt", 0, "Ptr", 0, "UInt", 3, "UInt", 0x2000000, "Ptr", 0, "Ptr")
MsgBox % R
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Lock a folder?

27 Aug 2017, 10:34

Flipeador wrote:

Code: Select all

DirName := A_Desktop . "\1"
R := DllCall("Kernel32.dll\CreateFileW", "Ptr", &DirName, "UInt", 2, "UInt", 0, "Ptr", 0, "UInt", 3, "UInt", 0x2000000, "Ptr", 0, "Ptr")
MsgBox % R
Hi Flipeador, would you mind to provide an "unlock"-option as well?! Thx for Ur effort :)
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Lock a folder?

27 Aug 2017, 11:31

BoBo wrote:Hi Flipeador, would you mind to provide an "unlock"-option as well?! Thx for Ur effort

Code: Select all

; https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx
DllCall("Kernel32.dll\CloseHandle", "Ptr", R)
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: Lock a folder?

27 Aug 2017, 20:48

Flipeador, still to test, but thanks!

Edit: Works great, thanks again! My intended use is to lock certain folders with a script running on a server, to prevent those root folders from being accidentally drag'n'drop'ed around by users who have open permissions for creating/deleting
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: [Solved] Lock a folder?  Topic is solved

28 Aug 2017, 09:59

so to expand on this, I would actually like to be able to lock from deletion/moving but still be accessible/stuff created/modified/deleted within... in short, the third parameter, dwShareMode = 3

https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Code: Select all

DirName := A_ScriptDir "\Test"
FileCreateDir, % DirName
R  := DllCall("Kernel32.dll\CreateFileW", "Ptr", &DirName, "UInt", 2, "UInt", 3, "Ptr", 0, "UInt", 3, "UInt", 0x2000000, "Ptr", 0, "Ptr")
MsgBox, Locked!
DllCall("Kernel32.dll\CloseHandle", "Ptr", R)
MsgBox, Unlocked!
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Giresharu, Google [Bot], Joey5, supplementfacts and 128 guests