你的listbox里的exe文件是全路径的吗?
如果是就试试下面的,如果不是就先找到全路径
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
ListBox1: TListBox;
PopupMenu1: TPopupMenu;
procedure menuclick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
exes:array of string;
implementation
{$R *.dfm}
procedure TForm1.menuclick(Sender: TObject);
begin
WinExec(PChar(exes[Tmenuitem(sender).Tag]),SW_SHOWNORMAL);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
item:Tmenuitem;
begin
PopupMenu1.Items.Clear;
setlength(exes,listbox1.Items.Count);
for i:=0 to listbox1.Items.Count-1 do
begin
exes:=listbox1.Items.Strings;
item:=Tmenuitem.Create(self);
item.Caption:=ExtractFileName(listbox1.Items.Strings);
item.Tag:=i;
item.OnClick:=menuclick;
PopupMenu1.Items.Add(item);
end;
end;
end.