Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close a program 1

Status
Not open for further replies.

Neovecchi

IS-IT--Management
Apr 2, 2002
21
0
0
NL
Hi There,

For my company I am trying to write a simple script, and with all the resources on the internet it goes quit well. The only thing I can't find is how to close a window. For example I open notepad with the following code:

Code:
function fnShellExecuteVB()

dim objShell
set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "Notepad.exe", "", "", "open", 1
set objShell = nothing

end functon

Now I want to close notepad in the same script. I don't think this is really difficult for experienced programmers, so can you help me out?

Thanks in advance,

Neovecchi
 
Code:
Set S = CreateObject("WScript.Shell")
Set X = S.Exec("Notepad.exe")
...
If X.Status = 0 Then X.Terminate()

Hope This Help
PH.
 
Hi PHV,

I think it will work, but what do you meen with the dots? And when is the status of x zero? Sorry I am not very well known with scripting, it quite new to me.

Regards,

Neovecchi
 
The dots are placeholder for your script logic.
The property Status of the WshScriptExec object return 0 when the executed task is still running, and 1 when it is finished.

Hope This Help
PH.
 
Hi PHV,

I tried the following I don't know if it is the correct way that's why I show you my code:
Code:
function fnShellExecuteVB()

dim objShell

Set S = CreateObject("WScript.Shell")
Set X = S.Exec("Notepad.exe")
set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "Notepad.exe", "", "", "open", 1
set objShell = nothing
If X.Status = 0 Then X.Terminate() 
	
end function

fnshellexecutevb()
This won't terminate the program.

Thanks,

Neovecchi
 
Code:
dim S, X
Sub LaunchNotepad()
  Set S = CreateObject("WScript.Shell")
  Set X = S.Exec("Notepad.exe")
End Sub
Sub QuitNotepad()
  If X.Status = 0 Then X.Terminate()
  Set X = Nothing
  Set S = Nothing
End Sub
Call LaunchNotepad
WScript.Sleep 10000
Call QuitNotepad

Hope This Help
PH.
 
Hi PHV,

It works, great, superb, wonderful, thank you.....

Kind regards,

Neovecchi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top