By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

Close Explorer windows

P: 10

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.

Mar 19 '08 #1
Share this Question
Share on Google+
4 Replies

P: 10
Anybody able to help?
Mar 20 '08 #2

Expert Mod 2.5K+
P: 2,545
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.

Mar 20 '08 #3

P: 10
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........
Mar 20 '08 #4

Expert 2.5K+
P: 2,653
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\system32\SHELL32.dll).

Expand|Select|Wrap|Line Numbers
  1. Public Sub CloseMyComputer()
  3.     Dim objShell As New Shell32.Shell
  5.     For Each w In objShell.Windows
  6.         If w.LocationName = "My Computer" Then w.Quit
  7.     Next
  9.     Set objShell = Nothing
  11. End Sub
Mar 20 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.