I'm trying to invoke the email program within a c# program based on .NET Framework 2.0, so I query the Registry, get the default email program and invoke it with System.Diagnostics.Process.Start, see the code below.
RegistryKey pRegKey = Registry.ClassesRoot.OpenSubKey(@"mailto\shell\open\command");
Debug.Assert(pRegKey != null);
string path = pRegKey.GetValue("").ToString();
int length =path.LastIndexOf(" ");
path = path.Substring(0,length);
path = path.Replace("\"", "");
pRegKey.Close();
System.Diagnostics.Process.Start(path);
The path at the last code is "C:\PROGRA~1\MICROS~2\Office12\OUTLOOK.EXE -c IPM.Note /m". I'm successfully to lunch it at the command line, but c# program reports the following error. I guess the reason is the "~" in the path, could you please let me know
how to fix it (not with hard code)? thanks.
System.ComponentModel.Win32Exception was unhandled
Message="The system cannot find the file specified"
Source="System"
ErrorCode=-2147467259
NativeErrorCode=2
StackTrace:
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
...