...

View Full Version : closing a program in VBScript.



thewillum
10-15-2007, 06:55 PM
Hey... I need some help safely closing a program, preferably using vbscript.

First, this is what I'm trying to do. I've got a program that creates a HUGE history database that is completely useless to me. I'm trying to close the program (which runs automatically on startup), delete the history.db, and restart the program. I have the scripts to delete the file and start the program, that's easy. I tried simply terminating the process, and that does end the program, but when restarting the program after terminating the process I get an error... I basically have to go "File > Exit" in order for the program to restart properly.

What I do not need is a script to terminate a process. I have that script.

I'd prefer to get this using vbscript, but would gladly use something else, however my programming knowledge is extremely limited.

Again, what I'm looking for is a script which would safely shut down a program as if I had used File>Exit.

Thanks if you can help.
-Bill

mic2100
10-16-2007, 09:51 AM
Try this



WScript.Quit [exitcode]

thewillum
10-16-2007, 02:07 PM
isn't that just going to terminate the script it's in? can it shut down a program?

ez4me2c3d
10-16-2007, 05:27 PM
Correct WScript.Quit just ends the script that is running.

What you are asking is, how to gracefully shutdown an application (such as Internet Explorer) via a VBScript. Correct?

The only way I know to do this is to launch the app from within the VBScript, then use the apps "shutdown" method. See example below:

set oIE = CreateObject("InternetExplorer.Application")
oIE.Navigate "about:blank"

Do
Loop While oIE.Busy

oIE.Visible = True

Do Until oShell.AppActivate("about:blank - Microsoft Internet Explorer")
Loop

oIE.Document.WriteLn "<html><head><title>Page Title</title></head><body><div id='output'>test</div></body></html>"

Set oDIV = oIE.Document.All("output")

'Wait 5 seconds then change the output int the window
Wscript.Sleep 5000

oDIV.InnerHTML = "I changed it"

'Wait 5 seconds then close the application
Wscript.Sleep 5000

oIE.Quit

thewillum
10-16-2007, 06:21 PM
What you are asking is, how to gracefully shutdown an application (such as Internet Explorer) via a VBScript. Correct?
Correct... and "Gracefully" is a good way to put it.

I don't think that opening and closing the program from within the same script will work for me, as this program is an "always-on" aside from the short period I want to shut it down to delete its history database.

I have had another suggestion that I'm working on right now, if that works I'll post it here...

Thanks for the responses.
-Bill

thewillum
10-16-2007, 07:01 PM
This article has a way that works perfectly for what I was trying to do... Thanks to those who tried to help.

http://www.codeproject.com/useritems/gopal_code.asp

Sam_123
05-26-2011, 09:10 AM
Dear all,

I need VB script which can help me to allow Force Internet Explorer to close, when system remails idle for 10 mins..

Thanks,:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum