Avatar of beauvoir2
beauvoir2
 asked on

Program Load

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

Avatar of undefined
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
ASKER CERTIFIED SOLUTION
JohnMcCann

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
beauvoir2

ASKER
Ok... but say i am like a newtork admin guy, how do i kind of make it do that for each machine on the network? Bonus marks for the answer!!!
beauvoir2

ASKER
Also... your modified code closes all the open windows, but as far as i can make out, neither of them stop you from opening another one!!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
JohnMcCann

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.
beauvoir2

ASKER
Yup, a timer works
Thanks