473,785 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to terminate process with VBA?

I use the default windows phone dialer to make calls from an Access form. I
close the phone dialer after the call is made using the below function. The
problem is I'm not closing the Phone Dialer application properly which
results in the Phone Dialer icon remaining in the system tray. I've tried
using the Windows API to refresh the system tray, but could not get that to
work.

How to I gracefully close the phone dialer application with VBA?

Private Function CloseDialer(str Dialer As String) 'note: strDialer =
"dialer.exe "
Dim objProcList As Object
Dim objWMI As Object
Dim objProc As Object
Set objWMI = GetObject("winm gmts:") 'create WMI object instance
If Not IsNull(objWMI) Then
Set objProcList = objWMI.Instance sOf("win32_proc ess") 'create object
collection of Win32 processes
For Each objProc In objProcList 'iterate through the enumerated
collection
If UCase(objProc.N ame) = UCase(strDialer ) Then objProc.Termina te
(0)
Next
End If

Thanks in advance.
Nov 13 '05 #1
4 21032
I checked Randy Birch's site, http://vbnet.mvps.org/, but didn't find
an answer. You might want to post in the VB newsgroup... maybe
someone else knows or I just missed it...
Nov 13 '05 #2
> I checked Randy Birch's site, http://vbnet.mvps.org/, but didn't find
an answer. You might want to post in the VB newsgroup... maybe
someone else knows or I just missed it...


Thanks for the tip. I think I need the window title in order to close it
properly (with the windows API). Now that I think about it, that's why I
originally wrote the code to just kill the process - there's no title on the
phone dialer window.
Nov 13 '05 #3
You do not need the WIndow Title just the Window's class name will do.
Deko is this the same issue I helped you with back in April?
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"deko" <de*****@hotmai l.com> wrote in message
news:vO******** *******@newssvr 27.news.prodigy .com...
I checked Randy Birch's site, http://vbnet.mvps.org/, but didn't find an answer. You might want to post in the VB newsgroup... maybe
someone else knows or I just missed it...
Thanks for the tip. I think I need the window title in order to close

it properly (with the windows API). Now that I think about it, that's why I originally wrote the code to just kill the process - there's no title on the phone dialer window.


Nov 13 '05 #4
> Deko is this the same issue I helped you with back in April?

You're correct (and I'm a bit embarrassed), you did help me with this
before. For some reason I had trouble with the code you posted in April and
I settled for a less than graceful termination of the dialer (which resulted
in the dialer icon remaining in the systray).

I'm now revisiting this module to make sure numbers are in canonical format
and also wanted to get rid of the extraneous dialer icon in the systray. I
forgot about our previous conversation.

In any case, I've gone back and reviewed the code you previously
recommended - and got it to work this time. But I'm having trouble
eliminating the "Are you sure?" dialog that appears when the code attempts
to close the dialer. Is there a way to send this dialog a "Yes" response?
(I sent you a working mdb)

Here's the code:

Option Compare Database
Option Explicit
Const WM_CLOSE = &H10
Const SW_HIDE = 0
'API use default Windows Phone Dialer
Private Declare Function tapiRequestMake Call _
Lib "TAPI32.DLL " _
( _
ByVal DestAddress As String, _
ByVal AppName As String, _
ByVal CalledParty As String, _
ByVal Comment As String _
) _
As Long
'API sleep to give user time to pick up phone
Private Declare Sub Sleep _
Lib "kernel32" _
( _
ByVal dwMilliseconds As Long _
)
'API find application by full caption
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindow A" _
( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) _
As Long
'API bring Window to foreground
Private Declare Function SetForegroundWi ndow _
Lib "user32" _
( _
ByVal hwnd As Long _
) _
As Long
'API send message to application
Private Declare Function PostMessage _
Lib "user32" _
Alias "PostMessag eA" _
( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long _
) _
As Long

Private Function CloseDialer(App Caption As String)
Dim hwnd As Long
hwnd = FindWindow(vbNu llString, AppCaption)
If hwnd <> 0 Then
'Bring to Front
SetForegroundWi ndow hwnd
'Close the app nicely
PostMessage hwnd, WM_CLOSE, 0&, 0&
'"Are you sure" dialog is received here
' how to send "Are you sure" dialog a Yes response?
'FindWindow ("Dialer") ???
'PostMessage hwnd, "Yes" ???
End If
End Function

Private Sub Telephone_Numbe rs_DblClick(Can cel As Integer)
On Error GoTo HandleErr
Dim objDialer As Object
Dim strMsg As String
Dim varReturn As Long
Dim intX As Integer
Dim varDialWait As Variant
Dim strDial As Variant
Dim j As Variant
Dim lngRetVal As Long
Dim i As Integer
Dim n As String
Dim p As String
Static blnDialing As Boolean 'prevent reentry into sub while dialing
DoEvents
If blnDialing Then Exit Sub
strDial = Trim$(Me!TelNum ber)
For i = 1 To Len(strDial)
n = Mid(strDial, i, 1)
If n Like "#" Then p = p & n
Next i
strDial = "+1" & Format(Left(p, 10), "(@@@)&&&-&&&&")
lngRetVal = tapiRequestMake Call(strDial, "", "", "faxback")
If lngRetVal = 0 Then
blnDialing = True
For intX = 1 To 8 'user has 8 seconds to pick up phone
DoEvents
Sleep 1000
Next
End If
Exit_Here:
On Error Resume Next
blnDialing = False
CloseDialer ("Phone Dialer")
Exit Sub
HandleErr:
Select Case Err.Number
Case 94 'Invalid Use of Null - if double-click on blank
'in this case, just open the dialer
Set objDialer = CreateObject("S cripting.FileSy stemObject")
If objDialer.FileE xists("c:\Progr am Files\Windows
NT\dialer.exe") Then
Call Shell("c:\Progr am Files\Windows NT\dialer.exe",
vbNormalFocus)
ElseIf objDialer.FileE xists("c:\Windo ws\dialer.exe") Then
Call Shell("c:\Windo ws\dialer.exe", vbNormalFocus)
End If
Set objDialer = Nothing
Exit Sub
Case Else
'modHandler.Log Err ("frm0Telephone "),
("Telephone_Num bers_DblClick")
End Select
Resume Exit_Here
End Sub
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
27498
by: Sean | last post by:
I can connect to a machine remotely with no problems but I'm having trouble trying to create a process remotely. Initially this was a perl and VB script which I'm converting to python. Its entire purpose is to start a process remotely. The problem initially was that the perl script could not 'see' any mapped drives as it would alway return 'access denied' so I'm trying to not only rewrite the script but fix this problem and my idea was...
0
1416
by: Neil Benn | last post by:
Hello, I'd make a call between the processes - you can have the deamon listen on a port and the GUI app can then send a shutdown message onto that port (there are obviously much fancier ways of doing this - I just picked the most bread and butter one). This will allow you to shut down your deamon in an organised fashion - I don't know if the terminate process functions calls the TerminateProcess function in the win32api but it is not a...
0
1217
by: RonB | last post by:
Hi all, I need to find a way to terminate processes running from a VB .NET program. So far I am able to terminate process running for the logged in user. I have not been able to terminate processes for other users, unless the account i am logged in a has admin privileges. I company security policy does not allow me to make these user part on the admin group. My idea was to run the VB .NET exe as the admin user, however the only way I've...
3
13786
by: Keith Grefski | last post by:
I cant seem to figure out how to terminate a process in vb.net i can do it using vbscript and wmi but terminate doesnt seem to exist in the available classes for wmi under vb.net
10
8499
by: shiry | last post by:
Hi, I need to do some important cleanup before my console application exists. I used the console ctrl event. This is working well and it fires for all cases, including the CTRL_CLOSE_EVENT (if I close the application from the X botton). But on the contrary to what the MSDN indicates (ms-help://MS.VSCC.2003/MS.MSDNQTR.2003OCT.1033/dllproc/base/handlerroutine.htm), ending my process from the task manager did not fire the CTRL_CLOSE_EVENT....
2
2371
by: SMichal | last post by:
Hi. how can I terminate process which was started with cmd /c ? The Kill() method terminates only that CMD.exe string cdHome = @"C:\Temp\"; string localhost = "chsaXY"; string userName = "aaa"; string password = "bbb"; string processFile = @"C:\Data.prc"; string temp = @"C:\Temp\"; string args = @" /c " + cdHome + "Notepad.exe " + " -n" + localhost + " -u"
9
16150
by: SeC | last post by:
Hi. Is there any way to detect if application is being killed by 'End Process' via Task Manager ?
8
3155
Atran
by: Atran | last post by:
Hello, in my pc, there is some processes cant terminate. When I click to a process end now, then click yes, after: pc show a error messagebox that cannot terminate that proecess. So How I can terminate the process? Thanks.
2
10804
by: John Bradley | last post by:
I've looked high and low, but I can't seem to find an answer. When I open an application using the shell command, as seen below, how can I close the application? I am creating a menu system for powerpoint presentations and they all loop. I need to stop one presentation before I staer another. I considered using New Process to start the application, but I don't seem to be able to pass command line arguments. ProcID = Shell("""C:\Program...
0
9643
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.