Avatar of rg001
rg001

asked on 

Making a task visible and the active window

How do I:   (1) find if a task is running (2) make the task visible if it is invisible and (3) maximize the task (make it the active window)?

Tasks are MSACCESS.EXE and/or WINWORD.EXE

An additional need is  if the task is WINWORD.EXE, and there are several documents open, how to make one of the documents visible and the active window?    (ex: Doc1, Doc2, and Doc3 are all open and let's say I want to make Doc2 the active visible document/window)

Regards.




VB ScriptMicrosoft AccessMicrosoft Word

Avatar of undefined
Last Comment
RobSampson
Avatar of sirbounty
sirbounty
Flag of United States of America image

Appactivate will make it the active window...see http://msdn.microsoft.com/en-us/library/wzcddbek(VS.85).aspx

Avatar of sirbounty
sirbounty
Flag of United States of America image

Here's somewhat of an example - will make the process active if it's found as running...
strProcess = "notepad"
 
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name='" & strProcess & ".exe'")
Set objShell = CreateObject("WScript.Shell")
 
If colProcessList.Count > 0 Then
  objShell.AppActivate strProcess
End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of rg001
rg001

ASKER

Rob, thanks for the code.   Here is what I see happening.

               Set objWord = GetObject("", "Word.Application")

When I have a Word document open, once the VBscript executes the above code, another instance of Winword.exe starts, thus 2 instances of Winword.exe appear in the task manager.

So if I understand what is happening, the       If LCase(objProcess.Name) = "winword.exe" ... statement is true when I have manually launched/opened a Word document, but for some reason the above GetObject is starting another instance of Winword.exe.

Roger
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of rg001
rg001

ASKER

Rob,

That was the answer.  Thanks, I appreciate it!

Roger
Avatar of rg001
rg001

ASKER

RobSampson always provides a usable solution!!!
Avatar of RobSampson
RobSampson
Flag of Australia image

Ah cool!  Great!  Sorry, I couldn't remember whether the first parameter was supposed to be empty or  null.

Thanks for the grade.

Regards,

Rob.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo