473,554 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Close a Program

7 New Member
Hi
I've opened a program using the code
Dim RetVal
RetVal = Shell("C:\Progr am Files\Outlook Express\msimn.e xe", vbNormalFocus)
Then i create file's and report's and send them off which works fine.
However now i want to close the Application, i've tried
Dim objOutlook As Object
Set objOutlook = CreateObject("O utlook.Applicat ion")
objOutlook.Clos e
but im being told "ActiveX component can't create object", am i missing an DLL have i gone the wrong about it all together?

Any thoughts would be appreciated!

Thanks
Jul 7 '07 #1
4 11502
JConsulting
603 Recognized Expert Contributor
Hi
I've opened a program using the code
Dim RetVal
RetVal = Shell("C:\Progr am Files\Outlook Express\msimn.e xe", vbNormalFocus)
Then i create file's and report's and send them off which works fine.
However now i want to close the Application, i've tried
Dim objOutlook As Object
Set objOutlook = CreateObject("O utlook.Applicat ion")
objOutlook.Clos e
but im being told "ActiveX component can't create object", am i missing an DLL have i gone the wrong about it all together?

Any thoughts would be appreciated!

Thanks
the shell command you're using simply launches the application...i t doesn't own it. You have two choices. You can use automation to "control" the application as it performs it's actions, or you can use your current method, but then you're going to have to delve into the world of killing PIDs Program ID numbers....much like going into the CTL-ALT-DEL and killing a process.
J
Jul 7 '07 #2
FishVal
2,653 Recognized Expert Specialist
the shell command you're using simply launches the application...i t doesn't own it. You have two choices. You can use automation to "control" the application as it performs it's actions, or you can use your current method, but then you're going to have to delve into the world of killing PIDs Program ID numbers....much like going into the CTL-ALT-DEL and killing a process.
J
You are right. The code below opens "notepad.ex e" and closes it via sending WM_CLOSE to all windows created by the process.

Expand|Select|Wrap|Line Numbers
  1. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  2.      (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
  3.      lParam As Any) As Long
  4.  
  5. Public Declare Function GetWindowThreadProcessId Lib "user32" _
  6. (ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long
  7.  
  8. Public Declare Function EnumWindows Lib "user32" _
  9.      (ByVal fpCallback As Long, ByVal lParam As Long) As Long
  10.  
  11. Public Const WM_CLOSE = 16
  12.  
  13.  
  14. Public Sub RunAndCloseApp()
  15.  
  16.     Dim lngProcID As Long
  17.  
  18.     lngProcID = Shell("notepad")
  19.     MsgBox "Notepad started, Ok to close it", vbOKOnly, "Close App"
  20.     CloseProcess lngProcID
  21.  
  22. End Sub
  23.  
  24.  
  25. Public Sub clbEnumWindows(ByVal hWnd As Long, ByVal lngParam As Long)
  26.  
  27.     Dim lngProcID As Long
  28.  
  29.     GetWindowThreadProcessId hWnd, lngProcID
  30.     If lngProcID = lngParam Then
  31.         'Debug.Print hWnd, lngProcID
  32.         SendMessage hWnd, WM_CLOSE, 0, 0
  33.     End If
  34.  
  35. End Sub
  36.  
  37.  
  38. Public Sub CloseProcess(ByVal lngProcID)
  39.     EnumWindows AddressOf clbEnumWindows, lngProcID
  40. End Sub
  41.  
  42.  
Jul 7 '07 #3
rossmrn
7 New Member
I keep on getting caught up on things that i forget to thank the people that replied
The above piece of code was just what i was looking for

Thank you !
Jul 12 '07 #4
FishVal
2,653 Recognized Expert Specialist
I keep on getting caught up on things that i forget to thank the people that replied
The above piece of code was just what i was looking for

Thank you !
Thanks for response. I'm glad it was helpful for you.
Jul 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
7333
by: Tian | last post by:
I have made a program in wxpython, but how could i exit the program? I am using wxFrame for my window, what is the function to close the program? Thanks!!
0
1361
by: Stewart Allen | last post by:
Hi there, I've got some code to open up an Excel workbook but what I want is for the code to pause until the Excel workbook is closed. Sub EditWorkbook(strFile as String) Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim strPath As String
2
2113
by: Palm Kevin | last post by:
Hello, I have a little problem when I try to use a class of a DLL. Example : I have a DLL with the object MTSync with a function Sync() I try in another program to use this dll like this : MTSync sync = new MTSync(); sync.Sync(); OK, now the problem: The problem is NOT that this does not work, it works great, it does everything it has...
1
1208
by: Alan Ho | last post by:
Dear All, i used some close program method, e.g. this.hide(), this.dispose() or this.close() , for above 3 method I dont know why i can't open the program in PPC again. and i dont want to use Application.exit() method, becase i use this method my program will hang on, does anyone has idea? thanks!
4
18097
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed as I find appropriate. I am using the socket asynchronously by calling the BeingSend and BeginReceive calls. I would like to be able to call...
7
2509
by: Alice | last post by:
Hi, In my program, the user can navigate to many different forms. When they go to the next form, I want the form they have left to close. However, the forms aren't closing. Can anyone tell me what I'm doing wrong? Here is a sample snippet of code where the user can return to the main form while simultaneously closing the previous form.
8
6435
by: koorb | last post by:
I am starting a program from a module with the Sub main procedure and I want it to display two forms for the program's interface, but when I run the program both forms just open and then program closes. Dim FORM1 As New Form1 Dim FORM2 As New form2 Sub main() FORM1.Show() FORM2.Show()
0
1370
by: Steve Ingram | last post by:
Found out what I'd done, and it wasn't py2exe causug the problem. I wasn't closing the main dialog properly, I was calling Close() instead of Destroy(), so the dialog stayed in memory, basically it was still running. Thanks for your help, steve -----Original Message----- From: Fredrik Lundh
6
2988
by: coolx | last post by:
Hi. I am using thread function in my project. When I close program.exe(form), it is still working at background and in task manager, i can see program.exe still working. How can I close this program completely? ----------------------------------------------------------- public void Form1_Load(object sender, EventArgs e) { ...
0
1199
by: winter28 | last post by:
When I try to close a window it will not close. If I have several windows open I get a pop up window that says close program, wait for program to respond, or let windows fix the problem. If I chose close program it closes everything I have open. It is very annoying!!!
0
7605
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7530
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7570
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7893
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6156
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3556
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
845
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.