Minimize Specific Window Using VBScript

I want a VBScript that checks all currently opens windows and if a specific window exists (by title) I want the script to minimize it.
Pretzel_JesusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tompa99Commented:
Hi there

Here is one example how you can do it in vbscript.

Regards Tompa

set shell = createobject("wscript.shell")
shell.AppActivate "Notepad"
 
wscript.sleep 2000
success = shell.appactivate("Notepad")
if success then shell.sendkeys "% n"  '...minimize
 
wscript.sleep 2000
success = shell.appactivate("Notepad")
if success then shell.sendkeys "% x"  '...maximize
 
wscript.sleep 2000
success = shell.appactivate("Notepad")
if success then shell.sendkeys "% r"  '...restore
 
wscript.sleep 2000
success = shell.appactivate("Notepad")
if success then shell.sendkeys "%{F4}"  '...maximize 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Robberbaron (robr)Commented:
Tompa is correct.

but you need to remember that AppActivate need the FULL title, or a Prefix or suffix of it.
this can have unexpected consequences

WSH help....
"In determining which application to activate, the specified title is compared  to the title string of each running application. If no exact match exists, any  application whose title string begins with title is activated. If an  application still cannot be found, any application whose title string ends with  title is activated. If more than one instance of the application named by  title exists, one instance is arbitrarily activated."

eg if you open a new notepad application. empty. then run the following scrip

set shell = createobject("wscript.shell")
 
'these return true ie -1'
y = "Notepad"
x = shell.AppActivate (y)
WScript.Echo y,x
 
y = "Untitled - Notepad"
x = shell.AppActivate (y)
WScript.Echo y,x
 
y = "Unti"
x = shell.AppActivate (y)
WScript.Echo y,x
 
y = "pad"
x = shell.AppActivate (y)
WScript.Echo y,x
 
y = "epad"
x = shell.AppActivate (y)
WScript.Echo y,x
 
'returns false 0'
y = "note"
x = shell.AppActivate (y)
WScript.Echo y,x
 
y = "d - N"
x = shell.AppActivate (y)
WScript.Echo y,x
 

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.