Re: Open Default Mail Client
From: Rob Kennedy (.)
Date: 01/15/04
- Next message: Ben Hochstrasser [FF]: "Re: Windows Share informations"
- Previous message: thomas pf: "Re: Windows Share informations"
- In reply to: Bryan Valencia: "Re: Open Default Mail Client"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 15 Jan 2004 16:16:08 -0600
Bryan Valencia wrote:
> procedure TMainForm.OpenDefaultEmailClient;
> var
> reg:TRegistry;
> DefaultMailClient, exeCommand:string;
> begin
> reg:=TRegistry.Create;
> try
> reg.RootKey:=HKEY_LOCAL_MACHINE;
> if reg.OpenKey('\SOFTWARE\Clients\Mail',false) then
Are you sure that will give you the current user's default e-mail
program? You can't get user-specific information from HKLM. Fetch the
current user's e-mail program from the same branch of HKCU, and then go
to HKLM to get the command line. Something like this:
RootKey := HKey_Current_User;
OpenKey('\Software\Clients\Mail', False);
DefaultMailClient := ReadString('');
RootKey := HKey_Local_Machine;
OpenKey(Format('\Software\Clients\Mail\%s\shell\open\command',
[DefaultMailClient]), False);
Command := ReadString('');
Also, use the OpenKeyReadOnly method instead of OpenKey. OpenKey will
fail if the user doesn't have write permissions in HKLM.
> begin
> DefaultMailClient := reg.ReadString('');
> reg.OpenKey(DefaultMailClient+'\shell\open\command',false);
> exeCommand := reg.ReadString('');
> exeCommand := Copy(exeCommand, Pos('"', exeCommand) + 1,
> Length(exeCommand));
> exeCommand := Copy(exeCommand, 1, Pos('"', exeCommand) - 1);
On my computer, you would be left with an empty string now. There are no
quotation marks in my command string, so Pos('"') returns 0, which means
you try to copy -1 characters.
Furthermore, by removing everything beyond the quotation mark (assuming
there is a quotation mark), you won't always get the e-mail program
anymore. Netscape and Mozilla both package the browser and the mailer in
the same program. They are differentiated by a command-line parameter.
With no parameters, the browser is started. Include the "-mail" argument
to start the mail program.
The "shell\open\command" value contains the *full* command line for
starting the mail program. You need to trust that value to be correct,
so just pass the whole string directly to ShellExecute or CreateProcess.
If the executable file name wasn't quoted but should have been, then the
API functions will probably figure it out for themselves. If they don't,
then it's not your problem; the mail program wasn't installed properly.
-- Rob
- Next message: Ben Hochstrasser [FF]: "Re: Windows Share informations"
- Previous message: thomas pf: "Re: Windows Share informations"
- In reply to: Bryan Valencia: "Re: Open Default Mail Client"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|