Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Sep : ShellExecute Default EMail Client on Windows Vista

www.cryer.info
Managed Newsgroup Archive

ShellExecute Default EMail Client on Windows Vista

Subject:ShellExecute Default EMail Client on Windows Vista
Posted by:"Bill Miller" (w2m..@hicomponents00.com)
Date:Sat, 1 Sep 2007 13:18:09

How to start the default email client on Windows Vista?

This fails:

ShellExecute(Handle, 'open', PChar('mail://' + Server1.Items[
Server1.ItemIndex ] ), nil, nil, SW_SHOW);

This fails:

procedure OpenMailClient;
const
  cMailClient = '\SOFTWARE\Clients\Mail\';
var
  reg: TRegistry;
  RegClientDefault: string;
begin
  reg := TRegistry.Create;
  try
    with reg do
    begin
      CloseKey;
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKeyReadOnly(cMailClient) then  RegClientDefault :=
reg.ReadString('');
      if OpenKeyReadOnly(cMailClient + RegClientDefault +
'\shell\open\command') then
        WinExec(PChar(ReadString('')), SW_SHOWNORMAL);
    end;
  finally
    reg.Free;
  end;
end;

This fails:
function GetMailClientOpenCommand(AMailClient: string): string;
const
  RegClientsRoot = '\SOFTWARE\Clients';
  RegClientsMail = '\Mail';
  RegClientsOpenCmd = '\shell\open\command';
var
  reg: TRegistry;
begin
  Result := '';
  reg := TRegistry.Create;
  try
    with reg do
    begin
      CloseKey;
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKeyReadOnly(RegClientsroot + RegClientsMail +
        '\' + AMailClient +
        RegClientsOpenCmd) then
        Result := reg.ReadString('');
    end;
  finally
    if Assigned(reg) then reg.Free;
  end;
end;

Replies:

www.cryer.info
Managed Newsgroup Archive