Hi, if a program is run, for example I.E, how do i say, if C:\Program Files\Internet Explorer\iexplore.exe is run then close it down?
Visual Basic Classic
Last Comment
beauvoir2
8/22/2022 - Mon
JohnMcCann
Open VB create new exe open the code window for form1 and paste the following.
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (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 WM_CLOSE = &H10
Private Sub Form_Load()
Dim hWindow As Long
hWindow = FindWindowEx(GetDesktopWindow(), ByVal 0&, "IEFrame", vbNullString)
If hWindow > 0 Then
PostMessage hWindow, WM_CLOSE, 0&, 0&
End If
End Sub
I aam not sure how you could stop someone starting a program in code. You would tend to this using the network setup. The only work around that springs to mind would be to use a timer, but that would not stop the program running, it would just tell it to quit each time the timer fires.
As for running the code over a network again I am not sure how you do that.
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (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 WM_CLOSE = &H10
Private Sub Form_Load()
Dim hWindow As Long
hWindow = FindWindowEx(GetDesktopWin
If hWindow > 0 Then
PostMessage hWindow, WM_CLOSE, 0&, 0&
End If
End Sub