Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing Deletion of files or Folders using API

Status
Not open for further replies.

pgk

Programmer
Jul 19, 2002
262
US
Hi,
I am trying to develop an application in VB that will allow users to specify the files or folders that they want to protect from unauthorised deletion.

I would like to know if there is some way to intercept the Delete operation in Windows ( may be using Sub Classing )and pass it onto the application that I am developing. If yes, what are the functions to be used?

Thanks a lot in advance. Hope it helps. Let me know what happens.
With regards,
PGK
 
Hi Folks,
Isn't there someone who can throw some light on this? I am desperatley waiting for your comments. Hope it helps. Let me know what happens.
With regards,
PGK
 
Hi,

I don't think this is possible at all if you are not running a NT based version of windows and in case you do, why don't you simply use the build in admin, power users, etc functions?
If you don't want to do that, you could use the CreateFile, SetNamedSecurityInfo and SetSecurityInfo API functions, but they just work at NT based versions of windows (you need the NTFS file system). You could also use the build in File Encryption options from Windows NT.

If you find a way on Windows 9x versions tell me.

For now I wish you good luck :)
 
Hi LukyLuke,
Thanks for your comments. But I am not familiar with this area. I would very appreciate it if you could elaborate on your points. Sorry for the trouble and thanks again. Hope it helps. Let me know what happens.
With regards,
PGK
 
OK, I've never done this before either, so I'll have to get into it a bit too, but you can find a lot of information about security with files and directories on the MSDN site. Just search for those functions and they give a lot of extra information rather than telling how the function works. For now I'll try to make an example.
 
The best solution might be to have the software make backups under a different name and have the original restored if it gets deleted.
There is wan API that watches folders for changes but I think it will just let you hear the BANG when the cow is already shot dead.

Private Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4
Private Const FILE_NOTIFY_CHANGE_DIR_NAME = &H2
Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
Private Const FILE_NOTIFY_CHANGE_SIZE = &H8
Private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10
Private Const FILE_NOTIFY_CHANGE_SECURITY = &H100
Private Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1 Or &H8 Or &H10 Or &H100
Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function FindNextChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function ResetEvent Lib "kernel32" (ByVal hEvent As Long) As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: 'E-Mail: KPDTeam@Allapi.net
Dim Ret As Long
'Set the notification hook
Ret = FindFirstChangeNotification("C:\", &HFFFFFFFF, FILE_NOTIFY_CHANGE_ALL)
'Wait until the event is triggered
WaitForSingleObject Ret, &HFFFFFFFF
MsgBox "Event Triggered for the first time"
'Reactivate our hook
FindNextChangeNotification Ret
'Wait until the event is triggered
WaitForSingleObject Ret, &HFFFFFFFF
MsgBox "Event Triggered for the second time"
'Remove our hook
FindCloseChangeNotification Ret
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top