Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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?
0
beauvoir2
Asked:
beauvoir2
  • 3
  • 3
1 Solution
 
JohnMcCannCommented:
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
0
 
JohnMcCannCommented:
This modified code closes all IE windows

Option Explicit

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
   
   Do
      hWindow = FindWindowEx(GetDesktopWindow(), ByVal 0&, "IEFrame", vbNullString)
      If hWindow > 0 Then PostMessage hWindow, WM_CLOSE, 0&, 0&
   Loop While hWindow > 0
End Sub



You could write a funcction that would shut down all insatances of an app

Private Sub CloseApp(lpClassName as string)
Dim hWindow As Long
   
   Do
      hWindow = FindWindowEx(GetDesktopWindow(), ByVal 0&, lpClassName, vbNullString)
      If hWindow > 0 Then PostMessage hWindow, WM_CLOSE, 0&, 0&
   Loop While hWindow > 0
End Sub



0
 
beauvoir2Author Commented:
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!!!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
beauvoir2Author Commented:
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!!
0
 
JohnMcCannCommented:
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.
0
 
beauvoir2Author Commented:
Yup, a timer works
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now