mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Politely Close all open windows

Author Message
Rischip

  • Total Posts : 519
  • Scores: 2
  • Reward points : 0
  • Joined: 3/26/2007
  • Status: offline
Politely Close all open windows Wednesday, June 13, 2007 9:37 AM (permalink)
0
 '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
 
 

<message edited by Rischip on Thursday, June 14, 2007 7:28 AM>
#1
    ebgreen

    • Total Posts : 8088
    • Scores: 95
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: Politely Close all open windows Thursday, June 14, 2007 2:53 AM (permalink)
    0
    Very handy.
     
    This chunk:
     
    If Not LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
       Set objShell = CreateObject("Wscript.Shell")
       objShell.Run WScript.ScriptFullName , 0, False
       WScript.quit
    End If
     
    would re-run the script with whatever the default engine is for that user. In my case, the default engine is CSCript. This means that it would essentially just keep killing itself and starting over. Instead then you should probably have it explicitly run itself with WSCript.exe.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
    #2
      Rischip

      • Total Posts : 519
      • Scores: 2
      • Reward points : 0
      • Joined: 3/26/2007
      • Status: offline
      RE: Politely Close all open windows Thursday, June 14, 2007 6:52 AM (permalink)
      0
      Yeah my mistake, I posted it before I fixed it.
       
      Ok, it's fixed.
      <message edited by Rischip on Thursday, June 14, 2007 7:30 AM>
      #3
        Fredledingue

        • Total Posts : 572
        • Scores: 0
        • Reward points : 0
        • Joined: 5/9/2005
        • Location: Europe
        • Status: offline
        RE: Politely Close all open windows Friday, June 15, 2007 6:10 AM (permalink)
        0
        Works like a charm!

        And personaly I like the fact that it doesn't requires WMI so that I can run it on my w98++ machine.
        Fred
        #4
          dm_4ever

          • Total Posts : 3673
          • Scores: 82
          • Reward points : 0
          • Joined: 6/29/2006
          • Location: Orange County, California
          • Status: offline
          RE: Politely Close all open windows Friday, June 15, 2007 12:37 PM (permalink)
          0
          If you're interested in seeing what else can be done with the word document regarding processes check this article out: http://www.microsoft.com/technet/scriptcenter/topics/office/tasks.mspx
          dm_4ever

          My philosophy: K.I.S.S - Keep It Simple Stupid
          Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
          Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
          #5
            robszar

            • Total Posts : 193
            • Scores: 0
            • Reward points : 0
            • Joined: 2/27/2005
            • Location:
            • Status: offline
            RE: Politely Close all open windows Wednesday, February 11, 2009 9:20 AM (permalink)
            0
            doesn't seem to work with office 2007, bombs here: Set objWord = CreateObject("Word.Application")

            *UPDATE*  It works, my bad
            <message edited by robszar on Thursday, February 12, 2009 7:25 AM>
            #6
              cippall

              • Total Posts : 30
              • Scores: 0
              • Reward points : 0
              • Joined: 2/3/2009
              • Status: offline
              Re:Politely Close all open windows Sunday, February 14, 2010 2:50 PM (permalink)
              0
              What about when you don't have Microsoft Word installed and you wanna search for a window with a specific title? 
              #7

                Online Bookmarks Sharing: Share/Bookmark

                Jump to:

                Current active users

                There are 0 members and 1 guests.

                Icon Legend and Permission

                • New Messages
                • No New Messages
                • Hot Topic w/ New Messages
                • Hot Topic w/o New Messages
                • Locked w/ New Messages
                • Locked w/o New Messages
                • Read Message
                • Post New Thread
                • Reply to message
                • Post New Poll
                • Submit Vote
                • Post reward post
                • Delete my own posts
                • Delete my own threads
                • Rate post

                2000-2012 ASPPlayground.NET Forum Version 3.8
                mbt shoes www.wileywilson.com