473,394 Members | 2,063 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,394 software developers and data experts.

Close a Shell executable

Hello,

I executed a .exe file from excel using the Shell() function
however, this program doesn't close on ending its calculations, so i want to close it from excel
Anyone an idea how to do this?

thank you in advance
jelle
Nov 5 '08 #1
2 9133
Dököll
2,364 Expert 2GB
Is this it?

Not my code but try it, will stop back to see where you. Or you can simply hang on, our experts will you and perhaps will come aid.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Explicit
  3.  
  4. Private Sub Command1_Click()
  5.     'open and write to bat file
  6.     Open "c:\test.bat" For Output As #1
  7.     Print #1, "dir c:\ >c:\test.txt"
  8.     Close #1
  9.     'create the file (test.txt) for output to be sent to
  10.     Open "c:\test.txt" For Output As #1
  11.     Close #1
  12.     'now shell to the bat file and then kill it
  13.     Shell "c:\test.bat", vbNormalFocus
  14.     Kill "c:\test.bat"
  15. End Sub
  16.  
  17.  
Nov 11 '08 #2
jg007
283 100+
I have had a look but cannot work out how to get a handle to the program but I have the code below which uses an imported dll to close a window based on the title, at the moment it opens notepad and then closes it when you click 'OK'

Expand|Select|Wrap|Line Numbers
  1.     Option Explicit
  2.  
  3.    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
  4.    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  5.    Private Const WM_QUIT = &H12
  6.  
  7.    Private Sub CommandButton1_Click()
  8.    Shell ("Notepad.exe")
  9.    MsgBox ("Click 'OK' to close notepad")
  10.     Dim sTitle As String
  11.      Dim iHwnd As Long
  12.      Dim ihTask As Long
  13.      Dim iReturn As Long
  14.      sTitle = "Untitled - Notepad"
  15.      iHwnd = FindWindow(0&, sTitle)
  16.      iReturn = PostMessage(iHwnd, WM_QUIT, 0&, 0&)
  17.      MsgBox "Notepad has been closed down"
  18.   End Sub
  19.  
Nov 11 '08 #3

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

Similar topics

1
by: Yaroslav Bulatov | last post by:
> Hi, > > Equis Uno wrote: > > > I use meta-x shell to start a shell and then once I see a shell > > prompt I enter the python command and I get a well-behaved python > > shell inside of emacs....
4
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
2
by: elziko | last post by:
I understand how to edit the registry to add context menu items in windows for any file type. I know I can use %1 for the default value of the command key to signify the filename that has been...
3
by: m.errami | last post by:
Hello all. I know the question will seem stupid but googling it gives me only stuff I don't care about. So the question is the following: When I start a python script containing a wxApp under...
3
by: George Sakkis | last post by:
I'm trying to figure out why Popen captures the stderr of a specific command when it runs through the shell but not without it. IOW: cmd = if 1: # this captures both stdout and stderr as...
2
by: NasirMunir | last post by:
I am trying to run an executable using shell. The executable look for certain files in the same directory and then run on those files. My problem: I have created a form which asks from the user to...
5
by: dg.google.groups | last post by:
Hi all, Is there any standard way to tell if the user is running from a module or from an interactive shell like IDLE or IPython? The best I've come up with so far is for a function to look at...
5
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
3
by: Max Vit | last post by:
I have come across a strange issue whilst trying to use a shell command call from Access and have spent some time trying to figure this out but can't find the cause as yet. The issue is: I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.