看一下C:\Autoexec.bat文件是否存在然后把fFlags标志设为
FOF_ALLOWUNDO OR FOF_NOERRORUI;
通过返回值来判断SHFileOperation函数是否执行成功。
FOF_NOERRORUI标志是用来关闭SHFileOperation函数内部错误提示

解决方案 »

  1.   

    看看这个例子好了:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      sPath:string;
      fsTemp:SHFILEOPSTRUCT;
      i:integer;
    begin
      sPath:=InputBox('文件操作','输入复制路径','c:\windows');
      if sPath<>''then begin
      fsTemp.Wnd := Self.Handle;
      file://设置文件操作类型
      fsTemp.wFunc :=FO_COPY;
      file://允许执行撤消操作
      fsTemp.fFlags :=FOF_ALLOWUNDO;
      for i:=0 to ListBox1.Items.Count-1 do begin
      file://源文件全路径名
      fsTemp.pFrom := PChar(ListBox1.Items.Strings[i]);
      file://要复制到的路径
      fsTemp.pTo := PChar(sPath);
      fsTemp.lpszProgressTitle:='拷贝文件';
      if SHFileOperation(fsTemp)<>0 then
      ShowMessage('文件复制失败');
      end;
      end;
    end;
     
      

  2.   

    p.pFrom := 'C:\autoexec.bat';在C++中可以这样写p.pFrom="C:\\autoexec.bat";改为p.pFrom="c:\\autoexec.bat\0\0";//添加两个'\0'字符只是Delphi形式我不知道怎么写.