Locking Files

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Location: Philippines
Contact:

Locking Files

Post by shadowslash » Sun Feb 21, 2010 5:35 am

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.... Image
Parañaque, Philippines
Image
Image

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Locking Files

Post by Mark » Tue Mar 02, 2010 9:47 am

shadowslash,

You could use VBScript to toggle the writable attibute. You can also toggle the visible and system attributes.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: Locking Files

Post by alemrantareq » Wed Mar 03, 2010 7:14 pm

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.

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Location: Philippines
Contact:

Re: Locking Files

Post by shadowslash » Sun Mar 07, 2010 11:25 am

@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
Parañaque, Philippines
Image
Image

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: Locking Files

Post by alemrantareq » Mon Mar 08, 2010 10:19 am

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? :lol:

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Location: Philippines
Contact:

Re: Locking Files

Post by shadowslash » Thu Mar 11, 2010 3:16 pm

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? :lol:
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. Image
Parañaque, Philippines
Image
Image

Post Reply

Return to “Windows”