Click here to Skip to main content
14,603,917 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi all,
please give me the logic to creat a folder lock using Win32 program.
what i mean by folder lock is, if any one is trying to open that
folder, it should ask for the password and if password is incorrect,
the folder should not be accessable...

Thank you..
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You will need a file system filter driver for this.
Here is a sample driver - http://www.eldos.com/cbflt/[^]

Here are some good reads about writing file system filter drivers -
File System Filter Driver Tutorial[^]
http://www.calsoftlabs.com/whitepapers/filter-driver.html[^]
http://msdn.microsoft.com/en-us/windows/hardware/gg462968[^]
   
Comments
[no name] 21-Mar-12 4:42am
   
Good! My 5 vote.
I think this is a perfect answer.
Guru_C++ 21-Mar-12 5:37am
   
Am having a lock.bat file that works exactly like folder lock.
lock.bat code is like this:
cls
@ECHO OFF
title Folder Locker
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Locker goto MDLOCKER
:CONFIRM
echo Are you sure u want to Lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to Unlock folder
set/p "pass=>"
if NOT %pass%==type your password here goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Locker
echo Locker created successfully
goto End
:End

Can anyone tell me, How can i do it in WIN32 ?
«_Superman_» 21-Mar-12 5:45am
   
The batch file simply does a rename followed by applying some attributes.
In Win32 you can achieve the same using the MoveFile API to rename a folder and the SetFileAttributes API to set the attributes on the folder.
Guru_C++ 21-Mar-12 6:28am
   
yes i used like this:
rename("E:\\locking.txt","E:\\new_locking.txt");

SetFileAttributes("E:\\new_locking.txt",FILE_ATTRIBUTE_HIDDEN);

After this, the file new_locking.txt will be hidden..

But when i go to Folder options->tools->view->Show hidden files. new_locking.txt file will be displayed. But it doesn't happen in the case of bat file. Any suggestion for this ?
«_Superman_» 21-Mar-12 6:36am
   
The batch file is also applying the system attribute.
So you need to apply the FILE_ATTRIBUTE_SYSTEM also.
Guru_C++ 21-Mar-12 6:56am
   
Am using like this :
SetFileAttributes("E:\\new_locking.txt",FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
Now also the file is visible..
Guru_C++ 21-Mar-12 7:26am
   
Actually i applied to Hidden & System to .txt file, So it was still visible.
But when i used like this:

char Path[]="E:\\MyDirectory123";
BOOL success;
success = CreateDirectory(Path, 0);
SetFileAttributes("E:\\MyDirectory123",FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);

Now MyDirectory123 is not Visible.Now my problem is solved. I guess Hidden & System attributes applies to Folder.

Thank you so much for helping.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100