Folder Guard

Posted On 2018-02-28 by ShayneCairns
Tags: VB6 Custom Functions VB6 Windows API VB6 System Services 
Views: 78

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 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 the Author

has posted a total of 1 articles.

Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links