473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Forcing Explorer to close open windows in C#

Is there any way to check for open Explorer windows and if any are found,
tell Windows Explorer to close them. I don't want a brute force method of
killing Explorer and letting it restart. I'd prefer something a little less
drastic. I suspect what I'm going to need is some API call such as
SendMessage. Anybody have any suggestions?
Nov 16 '05 #1
2 13139
"Paul Steele" <pa*********@acadiau.ca> wrote in message
news:uo**************@TK2MSFTNGP14.phx.gbl...
Is there any way to check for open Explorer windows and if any are found,
tell Windows Explorer to close them. I don't want a brute force method of
killing Explorer and letting it restart. I'd prefer something a little
less drastic. I suspect what I'm going to need is some API call such as
SendMessage. Anybody have any suggestions?


I found half the answer to my original question. By using a combination of
the Windows API calls FindWindow and SendMessage, it's quite simple to close
an open Exporer window:

int iHandle=Win32.FindWindow("ExploreWClass" ,windowName);
int j=Win32.SendMessage(iHandle, Win32.WM_SYSCOMMAND, Win32.SC_CLOSE,
0);

The part I haven't figured out is how to get the name of any open windows in
Explorer. Having just the class name is not enough to get the window
handle. Another API call I suspect...
Nov 16 '05 #2
"Paul Steele" <pa*********@acadiau.ca> wrote in message
news:O%****************@TK2MSFTNGP14.phx.gbl...
"Paul Steele" <pa*********@acadiau.ca> wrote in message
news:uo**************@TK2MSFTNGP14.phx.gbl...
Is there any way to check for open Explorer windows and if any are found,
tell Windows Explorer to close them. I don't want a brute force method of
killing Explorer and letting it restart. I'd prefer something a little
less drastic. I suspect what I'm going to need is some API call such as
SendMessage. Anybody have any suggestions?


I found half the answer to my original question. By using a combination of
the Windows API calls FindWindow and SendMessage, it's quite simple to
close an open Exporer window:

int iHandle=Win32.FindWindow("ExploreWClass" ,windowName);
int j=Win32.SendMessage(iHandle, Win32.WM_SYSCOMMAND, Win32.SC_CLOSE,
0);

The part I haven't figured out is how to get the name of any open windows
in Explorer. Having just the class name is not enough to get the window
handle. Another API call I suspect...


This code does what I want:

int wHandle;
while ((wHandle = Win32.FindWindow("ExploreWClass", null)) > 0)
{
Win32.SendMessage(wHandle, Win32.WM_SYSCOMMAND, Win32.SC_CLOSE, 0);
}
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sandy | last post by:
Hello - I have a little application that I would like to have an exit button on that closes my web application and closes Internet Explorer. What is the code that will do that? Any help...
1
by: Mike Kober | last post by:
I'm having difficulty getting this to work. Any help would be appreciated. What I'm trying to do is to open Explorer onto the Windows/fonts directory and then close it. I've added a font...
11
by: Wendy | last post by:
Hello, I have a program that does the following: When a user clicks on a row in a VB.NET datagrid, it will open a web page in Internet Explorer (that corresponds to that item in the selected row...
0
by: shinichi81 | last post by:
1. I create a background Windows Explorer (by using CreateProcess() function with szCmdline = "explorer.exe /select,C:\" and hidden option). After that, from Desktop, right click "My Computer"...
6
zybernau
by: zybernau | last post by:
hi, all in javascript i need to close all the child windows that i have opened through a parent window scenario: * here i will be having as many as child window opened and name given to...
2
by: jercha | last post by:
I have a form that allows users to open Windows Explorer and view folders based on a list of path names. I want to create code that will close all or a specific Windows Explorer screen. I...
2
by: =?Utf-8?B?ZGlncmVnYQ==?= | last post by:
After installing Microsoft Office 2007 + desktop search, Windows explorer began to give me all kinds of errors including a DR Watson, which I haven't seen since installing XP. I found a forum...
4
by: ginge6000 | last post by:
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...
3
by: Salad | last post by:
I have 2 apps; one written in A97, the other in A2003. If I open an app in A97 then close it, then open Explorer and dbl-click on the A2003 mdb, I'm informed it's an unrecognized format. If I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.