Jump to content

Close all windows script


Fredledingue

Recommended Posts

Thanks to a geek named Rischip on VBS forum

This script requires MS Word.

I think it can work on every windows.

Copy paste the code below into notepad and save it under Close_all_windows.vbs

'Author Rischip
'Home page [link=http://www.thegrimlinker.com]www.thegrimlinker.com[/link]
'This script closes all open windows on the workstation
'The script does not forcefully close applications
'therefore you will get a Save dialog on text editor apps and the like
'before they close
'This script requires Microsoft Word to be installed on your computer

On Error Resume Next

'check to ensure running under wscript
'if we are not it would be possible
'for the script to kill itself in the
'command window that cscript would have open
'if we are cool, if not relaunch under wscript

If Not LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "Wscript.exe " & WScript.ScriptFullName , 0, False
WScript.quit
End If

'create Word object
Set objWord = CreateObject("Word.Application")
'get collection of open windows
Set colTasks = objWord.Tasks
'enumerate open windows
'checking for visibility
'verify task is not program manager
'otherwise you will get the logoff/shutdown/restart window

for each objTask in colTasks
If objTask.Visible Then
If Not objTask.Name = "Program Manager" then
colTasks(objTask.Name).Close
End If
End If

next

objWord.Quit

Link to comment
Share on other sites


  • 4 weeks later...

Thank You.

This script actually closes windows in a "nice" way as well. If you've made edits to a document for instance. If the program offers the automated notification that the file has changed and to save it. You will get that prompt.

I use this script to close all windows "but", example: you can include the title "Inbox - Microsoft Outlook"

and if you are in Outlook on the Inbox page, it will not be closed. You can add any window title you wish.

Rischip

Link to comment
Share on other sites

  • 3 years later...

Folks,

I love this script!

Is there any way i can adapt this to "Windows 7"? I run it and it closes everything but also tries to log off of windows. I added a wscript.echo

for objTask.Name to see what was going on and it was saying "Program Manager" and then it said "Start". I tried getting it to ignore program manager and start, but it keeps trying to close those. processes. I'd love any help you can give me on this.

Thanks,

Randy

for each objTask in colTasks

If objTask.Visible Then

If Not objTask.Name = "Program Manager" then

wscript.echo objtask.name

colTasks(objTask.Name).Close

End If

End If

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...