<Preamble>
Using D6 Pro, Win2000pro
Basically I wish to run a shortcut from within a small program. I am
using D6's InstallShield Express to distribute my app, but I find the
executable files are not really copied to the target harddrive until
the desktop shortcut is clicked. So I am trying to "click" it with
this:
-------------
function GetDesktopDir: string;
var
pidl: pItemIDList;
nameBuf: Array [0..MAX_PATH] of Char;
csidlValue: Integer;
begin
csidlValue := CSIDL_DESKTOPDIRECTORY;
result := '';
if SUCCEEDED(SHGetSpecialFolderLocation(
Application.handle, csidlValue, pidl)) then
Begin
If pidl <> Nil Then
begin
If SHGetPathFromIDList(pidl, namebuf) Then
Result := StrPas(namebuf);
FreePidl(pidl);
end;
End;
end;
procedure TformMain.btnHailBrokerClick(Sender: TObject);
var
BatPath: string;
X: Integer;
begin
if btnHailBroker.Caption = 'Finish' Then
Begin
BatPath := GetDesktopDir;
BatPath := BatPath + '\HailBroker.lnk';
if FileExists(BatPath) then
begin
Shellexecute(0, 'open', PChar(BatPath), Nil, Nil, 0);
Close;
end
else
begin
//handle it
end;
End
Else //do other stuff
end;
---------------
</Preamble>
The problem on my machine and another similar machine (win2000pro) is
that nothing appears to happen, no errors, but the shortcut is not
executed. I *am* logged in as administrator.
I have tried ShellExecute without adding to the BatPath and using the
following "syntax" to no avail:
ShellExecute(0, 'open', 'HailBroker.lnk', PChar(BatPath), Nil, 0);
My program *can* execute "exe" and "bat" files okay, so I've created a
temporary bat file, then I execute that, which does work, but it seems
like a clumsy workaround:
---------
procedure TformMain.btnHailBrokerClick(Sender: TObject);
var
F: TextFile;
BatPath, TempPath: string;
X: Integer;
begin
if btnHailBroker.Caption = 'Finish' Then
Begin
TempPath := GetDesktopDir;
BatPath := TempPath+ '\HailBroker.lnk';
if FileExists(BatPath) then
begin
Try
AssignFile(F, 'StartBat.Bat');
Rewrite(F);
Writeln(F, '"' + BatPath + '"');
Finally
CloseFile(F);
End;
Sleep(1000); //unnecessary?, but whatever
Shellexecute(0, 'open', 'StartBat.Bat', Nil, Nil, 0);
Sleep(1000); //or this?
DeleteFile('StartBat.Bat');
Close;
end
else
begin
//handle it
end;
End
Else //do other stuff
end;
-----
Am I doing something wrong in the first case? Interestingly
InstallShield gives the option to execute the link upon completion of
the install, which doesn't work either. Does ShellExecute not work
with links(shortcuts) on Win2K? I've Googled and found answers, but I
can't get those answers to work. Any help/suggestions appreciated.
Thanks,
John
Typos are all mine....