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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a application from script...

Status
Not open for further replies.

Crowley16

Technical User
Jan 21, 2004
6,931
GB
this is probably a simple question, but I'm a newbie to vbScript so please humour me...

I would like to be able to close an open MSACCESS application normally, in a script.

I need it to be closed normally, and not to be "killed", is this possible?

Thanks

--------------------
Procrastinate Now!
 
Take a look at the GetObject function and the Quit method of the Access.Application object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
ah ha, it's as easy as that...

set acc = GetObject(, "Access.Application")
acc.Quit()

Now, Is there a way for this to close a specific instance of access?
I have tried to specify the full path of the open .mdb file in the first parameter, but it doesn't seem to work? should I be putting something else in there?

Thanks

--------------------
Procrastinate Now!
 
I've never tried it and it would be something of a hack, but you could try using the AppActivate method of the WshShell object to activate the instance that you want to close and give it focus. Then use the SendKeys method to send ALT-F4.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I guess I'll just stick to closing all instances of access, seems easier that way...

What I have now is:

Code:
'tests the Win32_Process to see if any instances of PHAAD is running
'if so, then quit access
set pro = CreateObject("WScript.Shell")
set ltr = CreateObject("WbemScripting.SWbemLocator")
set srv = ltr.ConnectServer()
set prs = srv.ExecQuery("SELECT Name, Description FROM Win32_Process WHERE Name = 'MSACCESS.EXE'")

for idx = 1 to prs.count
	[COLOR=red]msgbox "Update Now!"[/color]
	set pr = GetObject(,"Access.Application")
	pr.Quit
next 
	
'copy the most up to date front end from the server to local hdd
set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile srcPath, locPath
set fso = Nothing

'run the local updated front end
set AccInst = CreateObject("WScript.Shell")
AccInst.run accpath & mdbpath

and this works, however I had to put in the marked MsgBox line, because it would give me an error about can't create object if I didn't

any suggestions on why this would be?

Thanks

--------------------
Procrastinate Now!
 
Crowley16,

If you go that far, you should use .terminate method.
[tt]
for each oproc in prs
iret=oproc.terminate()
next
[/tt]
But make sure you "own" the process, else, you have to have the right _and_ explicitly assert the privilege of SeDebugPrivilege ({(debug)}). If you have further worries, monitor more closely the iret.

regards - tsuji
 
terminate? doesn't that force close the application, thus leaving .lbl temporary files everywhere?

I'm VERY new to vbScript, in fact, this is my first one ever, and just cobbled it together from a looking around for a couple of yours...

--------------------
Procrastinate Now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top