Search Tools Links Login

Folder Guard


With this code you can create a application that watches specified folders. When someone try's to access a folder that is being watched, the application closes the folder and displays an error message.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Const NILL = 0&
Const WM_SYSCOMMAND = &H112
Const SC_CLOSE = &HF060

'----------------------------------

Public Sub sFolderGuard(ByVal sWindow As String)
Dim sReadMessage As String

hWndX = FindWindow(vbNullString, sWindow)
sCloseWindow = SendMessage(hWndX, WM_SYSCOMMAND, SC_CLOSE, NILL)

If FindWindow(vbNullString, sWindow) Then

    MsgBox "Message",vbCritical,"Title"
    Exit Sub

End If

End Sub

Then on the form, maybe in a timer or something copy the following.

sFolderGuard "x" 'Where x is the name of the folder to watch

About this post

Posted: 2018-02-28
By: ShayneCairns
Viewed: 388 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.