Close Explorer windows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ginge6000
    New Member
    • Feb 2008
    • 10

    Close Explorer windows

    Hi,

    I have an app which creates batch files to transfer stuff around a network. As part of the batch files they disconnect the networked M:\ drive. Unfortunately if a WIndows Explorer/My Computer window is open showing the M:\ drive then the batch file bombs out (can't disconnect network drive while in use) and the VBA gets stuck in an endless loop waiting for the batch file to announce that it has finished.

    How can I check if any Windows Explorer/My Computer windows are open when the app first opens and then close them automatically?

    Cheers for your help.

    Ben
  • ginge6000
    New Member
    • Feb 2008
    • 10

    #2
    Anybody able to help?

    Comment

    • Stewart Ross
      Recognized Expert Moderator Specialist
      • Feb 2008
      • 2545

      #3
      Originally posted by ginge6000
      Anybody able to help?
      Sorry, ginge6000, this isn't really an Access issue at all, and the lack of response simply means that our contributors are not able to assist you with this one. We all check unanswered questions regularly and try our best to help if we have any useful suggestion to make.

      In your very particular circumstances you would probably need to use a windows API function to do what you ask. All I can suggest is that you check the Microsoft Knowledgebase for something like the FindWindow API call and see if you may be able to wrap this in VBA. Once you find the window you would need to close it - again another API call. Can't think of anything else you could do, really.

      -Stewart

      Comment

      • ginge6000
        New Member
        • Feb 2008
        • 10

        #4
        Sorry, I thought it was an Access issue as I am trying to do it in Access VBA. Ah well, back to google I go........

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #5
          Hi, there.

          You may use the following code though I couldn't prove it to be robust.
          You have to reference "Microsoft Shell Controls and Automation" library (\WINDOWS\syste m32\SHELL32.dll ).

          [code=vb]
          Public Sub CloseMyComputer ()

          Dim objShell As New Shell32.Shell

          For Each w In objShell.Window s
          If w.LocationName = "My Computer" Then w.Quit
          Next

          Set objShell = Nothing

          End Sub
          [/code]

          Regards,
          Fish

          Comment

          Working...