PC Review


Reply
Thread Tools Rate Thread

CreateProcess argument escape characters

 
 
Chance Hopkins
Guest
Posts: n/a
 
      9th Jun 2005
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/d...loverview.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
);


 
Reply With Quote
 
 
 
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      10th Jun 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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/d...loverview.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
> );
>



 
Reply With Quote
 
Chance Hopkins
Guest
Posts: n/a
 
      10th Jun 2005

"Peter Foot [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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/d...loverview.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
>> );
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Escape characters Alhambra Eidos Kiquenet Microsoft ASP .NET 0 13th Feb 2008 12:29 PM
mac and pc escape characters JJ Microsoft ASP .NET 4 26th Jun 2007 12:21 PM
Re: How to use CreateProcess() to pass argument. Chris Tacke, eMVP Microsoft Dot NET Compact Framework 0 7th Mar 2005 08:35 PM
What Happens To Escape Characters? Guadala Harry Microsoft ASP .NET 3 19th Aug 2004 03:59 AM
Escape characters =?Utf-8?B?Q2hlbg==?= Microsoft Access Queries 1 20th Apr 2004 11:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:48 PM.