?
Solved

Program Load

Posted on 2003-02-22
6
Medium Priority
?
166 Views
Last Modified: 2010-05-01
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
Comment
Question by:beauvoir2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 7999173
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
 
LVL 5

Accepted Solution

by:
JohnMcCann earned 120 total points
ID: 7999200
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
 

Author Comment

by:beauvoir2
ID: 7999256
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
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.

 

Author Comment

by:beauvoir2
ID: 7999273
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
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8000666
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
 

Author Comment

by:beauvoir2
ID: 8002109
Yup, a timer works
Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question