Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Locking files


  • Please log in to reply
13 replies to this topic

#1 Shadow Slash

Shadow Slash

  • Members
  • 25 posts
  • OFFLINE
  •  
  • Local time:09:25 AM

Posted 20 February 2010 - 11:01 PM

Um can anybody give me a starting ladder on how to lock files in a Windows environment... It can be through C++, VB, CMD Prompt, etc. or even the practical tips on how to achieve such? Any answer is greatly appreciated... :thumbsup:

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:06:25 PM

Posted 21 February 2010 - 12:16 AM

Perhaps you're looking for the LockFile function?

Billy3

EDIT: What exactly are you trying to accomplish?

Edited by Billy O'Neal, 21 February 2010 - 12:17 AM.

Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Keithuk

Keithuk

  • Members
  • 960 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:25 AM

Posted 21 February 2010 - 12:38 PM

It can be through C++, VB, CMD Prompt, etc.

But if your not using any of those what are you using? :thumbsup:

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#4 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:08:25 PM

Posted 22 February 2010 - 06:40 PM

Yes Billy made a valid point. What do you want to achieve ? The answer is totally depending on your goal.

#5 Shadow Slash

Shadow Slash
  • Topic Starter

  • Members
  • 25 posts
  • OFFLINE
  •  
  • Local time:09:25 AM

Posted 23 February 2010 - 04:04 AM

It can be through C++, VB, CMD Prompt, etc.

But if your not using any of those what are you using? :flowers:

What do you mean? I said "It can" not can't.

@billy and @romeo,
I'm trying to create a security software for my files so that my brothers can't access my files even though they snoop around trying to obtain my user password in the computer. I know I should use programs already made by other people but I want it to be specially made by me so that my programming skills would increase a little at least. :thumbsup:

EDIT:
@romeo, yeah it seems that's the correct link to the one I'm looking for but does anybody know how to implement this via VBScript? Like I'll just have the script be called by my program?

Edited by Shadow Slash, 23 February 2010 - 04:06 AM.


#6 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:08:25 PM

Posted 23 February 2010 - 05:48 AM

Yes the little brothers, they want to open each and every file and rack down all the secrets of your life.

Your goal deals more with encryption rather than locking a file. Locking a file would waste system resources in your case. A file in Windows is locked to prevent inadvertent changes made to it while your program is performing some operation on it. So it consumes lil bit of memory. And then how many files would you be locking ?

So my suggestion, specific to your goal, is that you either encrypt the files or change their read permissions. I do not know VBScript's capabilities but I do not think you can encrypt files other than XORing or ROT13 which are simple to beat.

You can use command line to remove all file permissions on a file or folder.
You should be an administrator. Open an elevated command prompt. Lets say you keep your files in C:\Docs. Then give command :
cacls C:\docs /G Administrators:F /T
This would wipe permissions for all other users except you (the Administrators group). Now type this :
cacls C:\Docs /D Administrators /T
Now all kinds of access even for you is denied. Try opening the folder, you will see. So now even if your kid brothers come to know your password they will not be able to access your files, unless they are very knowledgeable about Windows system security.
To gain access back, simply give the first command again (cacls C:\docs /G Administrators:F /T)

I have given example using cacls which works for XP, Vista and 7. Although Vista and 7 have newer Icacls command. But since I do not know what your Windows version is so....

Edited by Romeo29, 23 February 2010 - 10:26 PM.


#7 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:06:25 PM

Posted 23 February 2010 - 10:36 AM

Additionally, locking a file would not accomplish your goal because your lock exists only as long as your program is running. It's fairly difficult to actually enforce permissions with a lock because anyone who calls MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT toasts your lock. Unless somehow you get your application starting earlier than the client server subsystem (csrss.exe) which is not likely.

In addition to Romeo's answer: You can also modify permissions to files by right clicking on the file you wish to protect and use the GUI under the "security" tab.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#8 Shadow Slash

Shadow Slash
  • Topic Starter

  • Members
  • 25 posts
  • OFFLINE
  •  
  • Local time:09:25 AM

Posted 23 February 2010 - 09:06 PM

You can use command line to remove all file permissions on a file or folder.
You should be an administrator. Open an elevated command prompt. Lets say you keep your files in C:\Docs. Then give command :
cacls C:\docs /G:Administrators:F /T
This would wipe permissions for all other users except you (the Administrators group). Now type this :
cacls C:\Docs /D Administrators /T
Now all kinds of access even for you is denied. Try opening the folder, you will see. So now even if your kid brothers come to know your password they will not be able to access your files, unless they are very knowledgeable about Windows system security.
To gain access back, simply give the first command again (cacls C:\docs /G:Administrators:F /T)

Thank you so much! Just what I needed!

I have given example using cacls which works for XP, Vista and 7. Although Vista and 7 have newer Icacls command. But since I do not know what your Windows version is so....

I didn't quite get your statement here, um you're saying that the above example is compatible with XP, Vista and 7 right?

#9 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:08:25 PM

Posted 23 February 2010 - 10:28 PM

<<< I didn't quite get your statement here, um you're saying that the above example is compatible with XP, Vista and 7 right? >>>
Yes. The cacls command was deprecated in Vista and 7. Though still supported in Vista and 7, it is replaced by a newer command Icacls which, according to MS, is better.

Correction :
Okay I type an extra colon in this command after G : cacls C:\docs /G:Administrators:F /T Sorry, I noticed after reading you quoting my post.
The correct syntax is cacls C:\docs /G Administrators:F /T

#10 Shadow Slash

Shadow Slash
  • Topic Starter

  • Members
  • 25 posts
  • OFFLINE
  •  
  • Local time:09:25 AM

Posted 23 February 2010 - 11:55 PM

So in Vista and 7, I must use icacls because cacls is no longer there correct?

#11 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:08:25 PM

Posted 24 February 2010 - 06:25 AM

cacls is present in Vista and 7 and you can use it as I said before. Do not worry about it, the commands above will work in XP, Vista and 7.

#12 Shadow Slash

Shadow Slash
  • Topic Starter

  • Members
  • 25 posts
  • OFFLINE
  •  
  • Local time:09:25 AM

Posted 24 February 2010 - 09:55 PM

Won't vista and / or 7 alert or something like unwanted access etc. If this is done? I don't have any of those two yet so I'm asking...

#13 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:08:25 PM

Posted 25 February 2010 - 01:59 PM

Yes Access Denied message box pops up if you try to open a folder.

#14 Shadow Slash

Shadow Slash
  • Topic Starter

  • Members
  • 25 posts
  • OFFLINE
  •  
  • Local time:09:25 AM

Posted 26 February 2010 - 01:40 AM

Thanks for confirming... :thumbsup:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users