Launching a text file in windows 7 using process.start in C# is crashing the entire application

1) Develop a simple forms application( add one button and implement its button click handler with the following code)
2) System.Diagnostics.Process.Start("C:\\Test\\Example.txt");
3) Create the text file in the above specified path.
4) Now run the windows form application and invoke the button.
5) As observed, it is launching the text file and crashing the entire form application.

Can anybody please tell me the reason behind this problem ?

thanks !!!


Honorable Member
I tried it on Visual Studio 2010 Ultimate and had no problem. What version are you using?

Use Try...Catch to see where the problem is:

Also, place a debugging mark on your line of code and before it crashes, copy and paste here all the debugging lines from the Immediate window.

Last edited:
Thanks for the reply !!

Even i am using VS2010 Ultimate.May be the specifics are mentioned below,

Microsoft Visual Studio 2010
Version 10.0.30319.1 RTMRel
Microsoft .NET Framework
Version 4.0.30319 RTMRel
Installed Version: Ultimate

My Code Looks like this
private void button1_Click(object sender, EventArgs e)
//ProcessStartInfo startInfo = new ProcessStartInfo();
//startInfo.FileName = "iexplore.exe";
//startInfo.Arguments = "";
//startInfo.UseShellExecute = true;
catch (Exception ex) { MessageBox.Show(ex.Message); }

When i execute this it is not giving any exception and crashing up the parent process(form window).

Call Stack as you asked before crashing happens :

> TestHtmlCrash.exe!TestHtmlCrash.Form1.button1_Click(object sender, System.EventArgs e) Line 28 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e) + 0x70 bytes
System.Windows.Forms.dll!System.Windows.Forms.Button.OnClick(System.EventArgs e) + 0xa2 bytes
System.Windows.Forms.dll!System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent) + 0xac bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) + 0x2d1 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x93a bytes
System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WndProc(ref System.Windows.Forms.Message m) + 0x127 bytes
System.Windows.Forms.dll!System.Windows.Forms.Button.WndProc(ref System.Windows.Forms.Message m) + 0x20 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x13 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) + 0x64 bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) + 0x287 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) + 0x16c bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x31 bytes
TestHtmlCrash.exe!TestHtmlCrash.Program.Main() Line 18 + 0x1d bytes C#
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x6d bytes
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2a bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x63 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xb0 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x2c bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes
[Native to Managed Transition]


Honorable Member
Stack seems fine.
Try opening a VB Windows form and do the same: add a button and add the code. Code should look like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Open the text file
Dim FILE_NAME As String = ("C:\Test\Example.txt")
If System.IO.File.Exists(FILE_NAME) = True Then
MsgBox("File does not exist")
End If
End Sub

If the above works, we know it's a problem with C# and\or possibly Windows 7 + C# and we can take it from there. If not, it may be a bigger issue and we will look further into it.

I've tried executing vb windows forms application. Still facing the same issue.

One Observation :
When I try to launch applications like explore.exe, regedit.exe, notepad.exe which are part of C:\windows folder and iexplore.exe which is part of Program files directory I am facing the same issue (i.e., Parent process gets killed, when launching these applications using System.Diagnosis.Process.Start method. Note : Here parent process is a windows form that is crashing ). Other than that when i create my own exe and invoking it using Process.Start method is not causing any crash of parent process.

When i try to dig some more i came to know that Vista and Windows 7 has different security levels and which is causing this issue.

I launched windows forms program with administrator previliges only. But i am still facing an issue when spawning a new process using Process.Start method. That to when i launch applications from windows and Program files directory only causing the issue.


Honorable Member
Things to try:

The class in which you have written your code, to it add an attribute which grants the registry permission to the class......
02public class xyz
04 public xyz()
05 {
06 //here test wether the permission is available
07 if (System.Security.SecurityManager.IsGranted(new System.Security.Permissions.RegistryPermission(System.Security.Permissions.PermissionState.Unrestricted)))
08 {
09 //if the permission is granted then do watever u want to do
10 }
11 else
12 {
14 }
15 }

If this doesn't works then go to control panel -> administrative tools -> .net framework 2.0 configuration tool
from here grant your application or your assembly permission to read/write registries

If don't find 2.0 configuration tool then first install .net framework 2.0 on your computer.

Check this:
how to Run application as admin

Yea Right...: programmatic Runas in c#


Interesting... As specified in the how to Run application as admin link, i used ProcessStartInfo object and made Shellexecute to false then set the file info,arguments and passed that object to Process.Start method.

My program worked fine. without any parent process crash. But, still a doubt.. why this setting ShellExecute to false making it to work. What is the reasin behind it ? actually i did not give any admin user name and password. But setting up shellexecute to false itself making it to work.

Btw, Thanks for the suggestions... :)


Honorable Member
Glad to help.

This website is not affiliated, owned, or endorsed by Microsoft Corporation. It is a member of the Microsoft Partner Program.