Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to check background apps with VBSCRIPT??

137 views
Skip to first unread message

Jose L Pineda

unread,
May 20, 2001, 1:20:45 PM5/20/01
to
I need to start & run an application by using VBscript on some Win9.x
machines. But first, I'd like to check on whether Outlook, Word, IE, etc are
running before launching my app. If they are, I'd like to save(if needed) &
close them, if they are NOT, then I'd just launch my app. There will be no
user interaction during this process because the users will be out to lunch
when running the script and my app on a scheduler. Can anyone give some
sample code for checking (and closing) what other apps are running before
launching the app I want run? I am looking for something like "if x.app is
running, then save and close it; else run this other app". Or even
something like "close all apps currently running..." I need this because I
can't count on the users closing all their apps before walking away from
their PC's.
Thanks

--
Jose L. Pineda
josep...@earthlink.net


Duncan McC

unread,
Jun 16, 2001, 11:13:21 PM6/16/01
to
In article <N1TN6.2674$BN6.2...@newsread1.prod.itd.earthlink.net>,
josep...@earthlink.net says...

Have a look at this code that follows - it is to do a defrag - however
you'll note it has code to look at the Window title of a window, in
order to give it focus so that it can do it's send keys stuff. The idea
of this code is that the defrag program cannot be scheduled - but a vbs
file can, so this provides a method to do a scheduled defrag (and all
drives too). Can't recall where it came from - hope it's of use to
you...

'This script launches defrag and sends keys to the UI in order to
automate the defrag
'process.

set WshShell = CreateObject("WScript.Shell")

'Launch Defrag from the command line and wait for a second
WshShell.Run "dfrg.msc"
WScript.Sleep 1000

'Wait until the application has loaded - Check every second
While WshShell.AppActivate("Disk Defragmenter") = FALSE
wscript.sleep 1000
Wend


'modifications Alfonso
Dim oFSO, oDrives, oDrive, firstjump

set oFSO=createobject("scripting.filesystemobject")
set oDrives=oFSO.Drives
firstjump=0
'We use this variable to check if we have jumped first in the drive
list. It is necessary because the key sequence is a bit difference in
the first jump

for each oDrive in oDrives
if odrive.drivetype=2 then

'Bring the application to the foreground
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200

'Send an ALT-A key to bring down the degrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200

'Send a D to start the defrag
WshShell.SendKeys "D"

'Wait until the defrag is completed - Check for window every 5
seconds
While WshShell.AppActivate("Defragmentation Complete") = FALSE
wscript.sleep 5000
wend

'Bring the msgbox to the foreground
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200

'Send a tab key to move the focus from View Report button to the
Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500

'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500

'Bring the application to the foreground
WshShell.AppActivate "Disk Defragmenter"

WScript.Sleep 200

'Move down to next drive
if firstjump=0 then
WshShell.Sendkeys "{TAB}{DOWN}"
firstjump=1
else
WshShell.SendKeys"{DOWN}"
end if
end if
next

'Send and ALT-F4 to Close the Defrag program

WshShell.Sendkeys "%{F4}"

--
Duncan

0 new messages