473,499 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to: Trap System Message Dialog?

I want to be able to catch the exception thrown when trying to write to a
"locked" Usb drive.

For instance:

private void WriteToUsbDrive (string filePath, byte[] theBytes)
{
...
try
{
File.WriteAllBytes (filePath, theBytes);
}
catch (Exception ex) // Just for the example, assume only IO errors
occurred because the key is locked
{
MessageBox.Show ("Unlock the key!!!");
}
}
Testing on Vista, the system dialog will popup first telling the user that
the drive is locked, after clicking away that dialog, my dialog will then
appear - how can I prevent the OS system's dialog from appearing?

TIA
Jun 27 '08 #1
2 2238
On Fri, 20 Jun 2008 05:03:54 -0700, ESmith <el**********@hotmail.com>
wrote:
[...]
Testing on Vista, the system dialog will popup first telling the user
that
the drive is locked, after clicking away that dialog, my dialog will then
appear - how can I prevent the OS system's dialog from appearing?
I haven't tried this specifically with a "locked USB drive", but I suspect
that "locking" the drive just makes it read-only. So you should be able
to just check for it being read-only before you try to write to it.

If I recall correctly, there's an unmanaged API that controls whether
Windows presents an error message before failing an operation, but I
haven't used it since Windows 95. I'm not sure it'd even still be
supported. To some extent, if checking for read-only status isn't
suitable for your purposes, you probably should just trust the OS to deal
with things correctly. The question as to whether an error will be
presented to the user when a write to some device fails is really more a
contract between the user and the OS. An application intervening or
voiding that contract should do so only in the most unusual situations.

Pete
Jun 27 '08 #2
Peter Duniho wrote:
On Fri, 20 Jun 2008 05:03:54 -0700, ESmith <el**********@hotmail.com>
wrote:
>[...]
Testing on Vista, the system dialog will popup first telling the user
that
the drive is locked, after clicking away that dialog, my dialog will then
appear - how can I prevent the OS system's dialog from appearing?

I haven't tried this specifically with a "locked USB drive", but I
suspect that "locking" the drive just makes it read-only. So you should
be able to just check for it being read-only before you try to write to it.

If I recall correctly, there's an unmanaged API that controls whether
Windows presents an error message before failing an operation, but I
haven't used it since Windows 95. I'm not sure it'd even still be
supported.
SetErrorMode(). And yes, it still works fine. Though whether any SEM_ flag
has an effect on these particular dialog boxes is an open question.

--
J.
http://symbolsprose.blogspot.com
Jun 27 '08 #3

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

Similar topics

2
2730
by: aj | last post by:
DB2 WSE LUW 8.1 Fixpak 5 Red Hat AS 2.1 Has anyone ever seen a db2diag.log indicate that a trap file was written, but it is *not* written? For the 3rd time in 18 months, I had a production...
18
9007
by: Mantorok Redgormor | last post by:
What does a trap representation mean in the standard? And how can ~0 cause a trap representation? Could someone point out the relevant sections in the standard?
5
73175
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
10
10162
by: Bennett F. Dill | last post by:
Hi I'd like help writing a c# console app that can send an SNMP trap. I've seen some documents on writng an SNMP server, but I don't want to receive traps, I only want to send them. Thanks Ben
4
1274
by: Chris Botha | last post by:
If one wants to assure that there is only one instance of an app running, then the popular solution is to use a Mutex and a message box, telling the user there is already one running. I decided to...
1
5142
by: Ratz | last post by:
Hello everyone! I'm new to this Forum! I've spent about 56 hours trying to solve a .NET VB Runtime error while Using a program.Ive contacted the developer of the program and he could not figure out...
3
3956
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
6
2199
by: John | last post by:
In a form how I can I trap for the action that a user opens the built in 'find dialog'? I would like to trap for it and before the dialog shows up, I would like to execute some code, and after that...
0
1239
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, My C# application trys to access directorycontext during Form loading. Try and Catch if there is an exception. I then output an error message and then "this.Close();" to exit the...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.