Click here to Skip to main content
15,922,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I try to run wpf application on write proteced disk and i got error The disk cannot be written to because it is write protected. Please remove the write protection from the volume ....
As I notice there is no problem with run console application or win form application on write proteced disk - only wpf makes some troubles.
Notice: I cannot remove wire protection, so I'm looking for other solution.
Do anyone has any idea how to run it ?
Posted
Updated 18-May-11 4:05am
v5
Comments
Dave Kreskowiak 17-May-11 9:21am    
Since WPF doesn't have anything to do with writing to the disk, what is your app doing that's causing this error to show? Copy your Debug build to a write protected disk, launch it, then attach the Debugger to that process to find out where the problem is.
tklimczak 18-May-11 7:59am    
For test I create simple wpf project with empty screen, and I move it into pendrive. I change pendrive settings to "write proteced" mode. When I run this application I stll get this error - so wpf framework try to make some write operration.

1 solution

I found the solution for this problem :

C#
protected override void OnStartup(StartupEventArgs e)
{
    // SEM_FAILCRITICALERRORS = 0x0001
    // The system does not display the critical-error-handler message box. Instead, the system sends the error to the calling process.
    // Best practice is that all applications call the process-wide SetErrorMode function with a parameter of SEM_FAILCRITICALERRORS at startup. This is to prevent error mode dialogs from hanging the application.
    SetErrorMode(0x0001);
}

[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
private static extern uint SetErrorMode(uint uMode);
 
Share this answer
 
Comments
Dalek Dave 19-May-11 3:46am    
Nice feeling when you solve it!
Tarun.K.S 21-May-11 14:48pm    
Good job!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900