Page 1 of 1
Locking Files
Posted: Sun Feb 21, 2010 5:35 am
by shadowslash
Can anybody help me with locking up local files in a Windows platform? I tried "open file myFile" without
close file command but it would only prevent me from actually
deleting the opened file.. What I need for it to do is that when the user opens (E.g., a text file through notepad) it would display an "Access denied." error thus preventing the user from seeing the contents of the file. Thanks a lot for the replies in the future....

Re: Locking Files
Posted: Tue Mar 02, 2010 9:47 am
by Mark
shadowslash,
You could use VBScript to toggle the writable attibute. You can also toggle the visible and system attributes.
Best,
Mark
Re: Locking Files
Posted: Wed Mar 03, 2010 7:14 pm
by alemrantareq
shadowslash
You can hide any file or folder by changing its attribute. For example, I've a text file "Test.txt" in my desktop. I've changed its attribute by the following script -
Code: Select all
on mouseUp
put specialfolderpath(0) & "/Test.txt" into myFile
replace "/" with "\" in myFile
set the hideconsolewindows to true
get shell("attrib" && quote & myFile & quote && "+s +h")
end mouseUp
Now the text file become hidden system file. You can't see this file even you check "Show hidden files and folders" from Folder Options.
To get it back, just change the last line to -
Code: Select all
get shell("attrib" && quote & myFile & quote && "-s -h")
Note: If you uncheck "Hide protected operating system files (Recommended)" from Folder Options, then the file or folder can be seen even it is in hidden mode.
Re: Locking Files
Posted: Sun Mar 07, 2010 11:25 am
by shadowslash
@alemantareq, I know about that command line switch. It's just not the one I've been looking for, anyway, I've found the solution and is now happy with it. I've made
Lock It!.
You can get the Windows-only version at:
http://www.mediafire.com/file/zmbjncmmy ... t_1-00.exe
Re: Locking Files
Posted: Mon Mar 08, 2010 10:19 am
by alemrantareq
shadowslash
You really done an excellent job! Once upon a time, it was also in my mind. Can you share a little how you've made it?

Re: Locking Files
Posted: Thu Mar 11, 2010 3:16 pm
by shadowslash
alemrantareq wrote:shadowslash
You really done an excellent job! Once upon a time, it was also in my mind. Can you share a little how you've made it?

Here's a snippet from the code I used in the Lock button.
Code: Select all
put empty into tError
set the itemDel to backslash
cmd ("cacls" && quote & tLine & quote && "/d Everyone /e")
if the result is "The Cacls command can be run only on disk drives that use the NTFS file system." then
put "The drive <b>" & item 1 of tLine & "\" & "</b> is invalid. Please transfer the file or folder to another drive." into tError
else if line 1 of the result is ("The system cannot find the file specified.") then
put "The file or folder defined does not exist or has already been moved to a different location." into tError
else if line 1 of the result is ("The device is not ready.") then
put "The drive <b>" & item 1 of tLine & "\" & "</b> is not yet mounted or is not existent." into tError
else if line 1 of the result is not ("processed file: " & tLine) and \
line 1 of the result is not ("processed dir: " & tLine) then
put the result
put "An unknown error occured while processing file or folder." into tError
end if
if tError is not empty then
answer warning tError with "Continue" titled tLine
end if
From there, you can see that it's all just a little bit of command line passing and result processing. The rest is done by the operating system itself.
