How to lock specific drive or folder or file?

This is a discussion on How to lock specific drive or folder or file? within the C# Programming forums, part of the General Programming Boards category; Hello, I just wanted to how can i make my application lock certain drives or folder or file? and make ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    225

    How to lock specific drive or folder or file?

    Hello,

    I just wanted to how can i make my application lock certain drives or folder or file? and make it unaccessible to all applications till my application does not turn off the lock? Please provide me some hints so i can proceed on making my application.

    Thanks in advance
    Last edited by chottachatri; 08-06-2009 at 04:49 AM.

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Open a certain file and specify the share mode. I'm not sure about directories.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    NO! that doesn't work out, because it occupies memory i just want to place a lock on it (and even make it invisible), and perhaps not only for files but also for folders and whole drives.

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    ... >_>

    You need to better specify your question. valaris answered exactly what you asked. Now you are asking something different. Do you want to hide files, & keep people from accessing them? If so, why not use an encrypted partition/file?
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    hello Cactus,

    Kindly read my post first..

    "Hello,

    I just wanted to how can i make my application lock certain drives or folder or file?"

    does valaris solution work for folder or drives?

  6. #6
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    And why not? In Linux, a file is a drive, so yes, it does. I would expect Windows to behave similarly -- is a drive not a HANDLE of some sort? I believe there are paths to open a drive with the proper invocation of CreateHandle(). The equivalent may or may not be possible in C#, not at least without some difficultly. Access could not be parallel -- two things writing to the same drive at the same time would be chaos.

    At any rate, you've missed my point. A simple clarification was needed to your original post. Furthermore, I still feel your second post clouds the issue, specifically:
    Quote Originally Posted by chottachatri
    because it occupies memory i just want to place a lock on it (and even make it invisible)
    What is it? A file generally does not reside in memory -- it resides on disk. While it is possible to have a file or a file's contents in memory, I am unsure of what you mean here.

    I suppose a proper kernel-land hook could block the presence of a file, likewise, if you could embed code in user-land processes and capture calls to the proper system calls. However, masking the presence of a file or directory is similar to the behaviour of a root kit. Just why do you want to hide a file?

    Proper file permissions and/or holding the file open would probably fill you need, which, we have no idea about. Perhaps you should... clarify, and tell us what you're trying to accomplish?

    And just what would "locking" a directory do?
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    In linux everything is a file. I am not a Linux user.
    Say suppose i have some private things in my folder or drive and i want to lock it then how to do it?See this link you will get better idea of what i want to create and why i want to create.

    Hide Folders XP - Files and Folders Password Protection - Hide Folder Lock Folder Password Protect Folder - FSPro Labs

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    I'd suggest you use file/directory permissions then (only works on NTFS).
    And catcus: you are way off on how Windows work. Directories aren't files, and handles aren't drives/directories. CreateHandle creates a new handle, but not a directory/drive. I don't even know if it's possible to open a directory to lock it.
    Nevertheless, these solution would require the app to permanently reside in memory since as soon as it closes, the locks go away.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Thanks Elysia! you got what i wanted to do.
    This cactus is really a cactus on this forum. Everytime i post my query he behaves as though he knows everything and misguides newbies in such a way that they themselves forget what was their query and think twice before posting another query!

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    I wouldn't go around badmouthing members of the board, however.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    And catcus: you are way off on how Windows work. Directories aren't files, and handles aren't drives/directories. CreateHandle creates a new handle, but not a directory/drive. I don't even know if it's possible to open a directory to lock it.
    There was a slight typo on my part -- I meant CreateFile(), not CreateHandle (which is not a Win32 API function, to my knowledge). With CreateFile(), you can open a drive, ie:
    When opening a physical drive x, the lpFileName string should be the following form: \\.\PhysicalDriveX. Hard disk numbers start at zero.
    ...which was the point of my post. Unfortunately, the typo makes it rather confusing.

    In linux everything is a file. I am not a Linux user.
    No, and I was quite aware of that. It was an analogy -- the two systems are quite similar in some respects. This is one of them. In Linux, both drives & files are openable as files. It is the same in Windows.

    I never equated a directory to a file, nor said you could open it to lock it, in fact, read the last line of that post. I was attempting to both get clarification from the OP, and suggest possible things he/she was looking for. It would seem that the answer was, in fact, one of the things I listed. Apparently, I merely confused the issue - my apologies.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Quote Originally Posted by Cactus_Hugger View Post
    There was a slight typo on my part -- I meant CreateFile(), not CreateHandle (which is not a Win32 API function, to my knowledge). With CreateFile(), you can open a drive, ie:

    ...which was the point of my post. Unfortunately, the typo makes it rather confusing.
    Aha! That makes more sense.
    I am unsure of how much CreateFile can actually do (miserably misnamed function!), but you're probably correct or not far off.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 04:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21