I'm using CreateProcess to launch an email and it's going pretty well.

The only problem im having is that my arguments are causing errors.

My string looks something like this:

(this function calls the proper api below)

CreateProcess("tmail.exe",
"-to \"" + UserEmail + "\" " +
"-subject \"" + subject + "\" " +
"-body \"" + body + "\"");


if the body string has a " or - in it I seem to get some errors. I'm
assuming I should escape them. I tried using \" and \- but that doesn't seem
to be working right.

I read here from this page about the xp shell the following

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx

You can use most characters as variable values, including white space. If
you use the special characters <, >, |, &, or ^, you must precede them with
the escape character (^) or quotation marks. If you use quotation marks,
they are included as part of the value because everything following the
equal sign is taken as the value.

So I tried ^'s and that didn't work either.

Anyone know what the reserved characters are and what the escape character
or sequence is?

Thanks for any help.


----------------------------

[DllImport("Coredll.dll")]
public extern static IntPtr CreateProcess(
string imageName,
string cmdLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
Int32 boolInheritHandles,
Int32 dwCreationFlags,
IntPtr lpEnvironment,
IntPtr lpszCurrentDir,
IntPtr si,
//byte [] si,
ProcessInfo pi
);

Re: CreateProcess argument escape characters by Peter

Peter
Thu Jun 09 17:36:17 CDT 2005

In order to make your code more portable (on some devices the email app was
pmail.exe, on most others it's tmail.exe) you could instead call
createprocess with a mailto: url link. You'll need to encode this with
appropriate escape characters, and you can make use of the System.Uri class
to help do this for you.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.peterfoot.net | www.opennetcf.org

"Chance Hopkins" <chance_hopkins@hotmail.com> wrote in message
news:udyWwiTbFHA.464@TK2MSFTNGP15.phx.gbl...
> I'm using CreateProcess to launch an email and it's going pretty well.
>
> The only problem im having is that my arguments are causing errors.
>
> My string looks something like this:
>
> (this function calls the proper api below)
>
> CreateProcess("tmail.exe",
> "-to \"" + UserEmail + "\" " +
> "-subject \"" + subject + "\" " +
> "-body \"" + body + "\"");
>
>
> if the body string has a " or - in it I seem to get some errors. I'm
> assuming I should escape them. I tried using \" and \- but that doesn't
> seem to be working right.
>
> I read here from this page about the xp shell the following
>
> http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx
>
> You can use most characters as variable values, including white space. If
> you use the special characters <, >, |, &, or ^, you must precede them
> with the escape character (^) or quotation marks. If you use quotation
> marks, they are included as part of the value because everything following
> the equal sign is taken as the value.
>
> So I tried ^'s and that didn't work either.
>
> Anyone know what the reserved characters are and what the escape character
> or sequence is?
>
> Thanks for any help.
>
>
> ----------------------------
>
> [DllImport("Coredll.dll")]
> public extern static IntPtr CreateProcess(
> string imageName,
> string cmdLine,
> IntPtr lpProcessAttributes,
> IntPtr lpThreadAttributes,
> Int32 boolInheritHandles,
> Int32 dwCreationFlags,
> IntPtr lpEnvironment,
> IntPtr lpszCurrentDir,
> IntPtr si,
> //byte [] si,
> ProcessInfo pi
> );
>



Re: CreateProcess argument escape characters by Chance

Chance
Fri Jun 10 03:35:33 CDT 2005


"Peter Foot [MVP]" <feedback@nospam-inthehand.com> wrote in message
news:%23C3KqOUbFHA.3840@tk2msftngp13.phx.gbl...
> In order to make your code more portable (on some devices the email app
> was pmail.exe, on most others it's tmail.exe)

thanks for the good tips, the code is actually like this:

string MailProg = "tmail.exe";

if(System.IO.File.Exists("\\Windows\\pmail.exe"))
MailProg = "pmail.exe";

I snipped it a bit for brevity. I'm always feeling like I paste WAY TOO MUCH
code.

you could instead call
> createprocess with a mailto: url link. You'll need to encode this with
> appropriate escape characters, and you can make use of the System.Uri
> class to help do this for you.

I tried this but ended up manually don't a bunch of .Replace("","") cause it
doesn't work with the Uri class for some reason. You are right on with the
concept though. This got is working for me. I'm still debugging a bit and
looking for some character. I have about 2% of them not working, but the
rest do. I can't get any to work if I do a straight:

return new System.Uri(val).ToString();

from a function. I'll try to get something logical together tomorrow and
post it if I figure anything out.

Thanks for the help.


>
> Peter
>
> --
> Peter Foot
> Windows Embedded MVP
> www.inthehand.com | www.peterfoot.net | www.opennetcf.org
>
> "Chance Hopkins" <chance_hopkins@hotmail.com> wrote in message
> news:udyWwiTbFHA.464@TK2MSFTNGP15.phx.gbl...
>> I'm using CreateProcess to launch an email and it's going pretty well.
>>
>> The only problem im having is that my arguments are causing errors.
>>
>> My string looks something like this:
>>
>> (this function calls the proper api below)
>>
>> CreateProcess("tmail.exe",
>> "-to \"" + UserEmail + "\" " +
>> "-subject \"" + subject + "\" " +
>> "-body \"" + body + "\"");
>>
>>
>> if the body string has a " or - in it I seem to get some errors. I'm
>> assuming I should escape them. I tried using \" and \- but that doesn't
>> seem to be working right.
>>
>> I read here from this page about the xp shell the following
>>
>> http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx
>>
>> You can use most characters as variable values, including white space. If
>> you use the special characters <, >, |, &, or ^, you must precede them
>> with the escape character (^) or quotation marks. If you use quotation
>> marks, they are included as part of the value because everything
>> following the equal sign is taken as the value.
>>
>> So I tried ^'s and that didn't work either.
>>
>> Anyone know what the reserved characters are and what the escape
>> character or sequence is?
>>
>> Thanks for any help.
>>
>>
>> ----------------------------
>>
>> [DllImport("Coredll.dll")]
>> public extern static IntPtr CreateProcess(
>> string imageName,
>> string cmdLine,
>> IntPtr lpProcessAttributes,
>> IntPtr lpThreadAttributes,
>> Int32 boolInheritHandles,
>> Int32 dwCreationFlags,
>> IntPtr lpEnvironment,
>> IntPtr lpszCurrentDir,
>> IntPtr si,
>> //byte [] si,
>> ProcessInfo pi
>> );
>>
>
>