Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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[^]
 
Share this answer
 
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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900