473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Stop a running .EXE in VBA

Is there a command that works like the opposite of Shell(Pathname)?
I need to stop a running .exe when certain events occur on my Access
form. Thanks

Nov 13 '05 #1
3 2815
On 28 Mar 2005 14:29:20 -0800, "Tommy T-Bag" <th***********@gmail.com>
wrote:

You can nuke the app out of memory (just like End Task), but a more
elegant way is to post a WM_CLOSE message using the PostMessage
windows API.

-Tom.

Is there a command that works like the opposite of Shell(Pathname)?
I need to stop a running .exe when certain events occur on my Access
form. Thanks


Nov 13 '05 #2
I am not able to get this to work.
I also tried CloseHandle from kernel32.dll
and TerminateProcess.

Based my code on the following examples:
http://www.andreavb.com/tip020021.html
http://www.thevbzone.com/modShellCommand.bas

No luck.
This is driving me nuts.

The reason I need this is to try to "integrate"
a C#.NET form into an Access .adp application.
So that I can click a button in my Access menu,
seamlessly open my .NET form (no problem so
far) but ensure that the .NET form closes if the
user closes their Access window.

A convoluted requirement I know.

Nov 13 '05 #3
Got it working.

Here is the code:

Private Declare Function TerminateProcess Lib "kernel32.dll" _
(ByVal hHandle As Long, _
ByVal uExitCode As Integer) As Boolean

Private Declare Function CloseHandle Lib "kernel32.dll" _
(ByVal hObject As Long) As Boolean

Private Declare Function OpenProcess Lib "kernel32.dll" _
(ByVal lngAccessType As Long, _
ByVal blnInheritHandle As Boolean, _
ByVal lngProcessID As Long) As Long

Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const SYNCHRONIZE = &H100000
Private Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or _
SYNCHRONIZE Or &HFFF

Private Sub _
Example() ' runs and terminates an executable
Dim bl As Boolean
Dim dbl As Double
Dim hProcess as Long
Dim uExitCode as Integer
dbl = Shell("C:\myFile.exe", vbNormalFocus)
MsgBox "Im sleeping" ' just so you can see it happening
Me.hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, dbl)
bl = TerminateProcess(Me.hProcess, Me.uExitCode)
Call CloseHandle(Me.hProcess)
End Sub

Nov 13 '05 #4

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

Similar topics

5
by: Ketta | last post by:
I want to make a simple simple asp page. All I want is when the page loads it does "net stop <service>". The code is below, it is not running as IUSR_<machine>, I am authenticating as...
0
by: Rick | last post by:
I am trying to stop the screen saver from running based on a external trigger from our application. I have a .Net application and I am using interop to make a SystemParameterInfo() call to...
5
by: Paul O. Morris | last post by:
Is there a script that I can run to stop a particular SQL server service on Win2003 server? I'm looking for a similar script to restart that service as well. Thanks.
2
by: Adrian MacNair | last post by:
Hi I need some help if anyone can understand my crap javascript. The problem is that after the slideshow ends (reaches the end of array) it should stop, but the timeout doesn't clear and I can see...
2
by: Prasad | last post by:
Hi, I am writing a service which takes a long time to stop after the OnStop call is given by the Services Snap-in. The problem is I cannot cut down on the time that it takes to Stop. The Service...
2
by: Martyn Fewtrell | last post by:
Dear All I have a Windows 2003 Server with IIS6 where the validation controls on ASP.Net pages no longer work. I believe it to be specific to the server as if I create an ASP.Net page on the...
7
by: dotnetprogrammer via DotNetMonster.com | last post by:
I have an NT Service written in c# (.net framwork 2.0). When it hits a certain error condition, I want it to be to cause itself to stop. How can I do this? -- Message posted via...
0
by: mattcfisher | last post by:
Hi, I have two windows services running together. One is the main program, and one is an "updater" wrapper for the main. The updater service starts and stops the main one (as in you should never...
0
by: =?Utf-8?B?am1hZ2FyYW0=?= | last post by:
My program needs to do X when someone 'starts using' their Windows user account, and it should do Y when they 'stop using' their Windows user account. By 'starts using' I mean they log on, unlock...
33
by: Sunny | last post by:
Hi, Sometime, when your script is too big, IE Gives you a warning "Stop Running This Script" A script on this page is causing Internet Explorer to run slowly. Does anyone knows, How to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.