要用程序运行别人的exe程序。发现用  winexec(Pchar(strPath),SW_SHOW); 或者  ShellExecute(handle,'open',Pchar(strPath),nil,nil,SW_SHOWNORMAL); 有很多别人的exe程序都无法打开。但我用鼠标直接点击却可以, 在 "运行" 里输入程序的路径也可以打开,但就是用 winexec 和shellExecute 打不开。而且有好几个这样的程序。有没有比较好的调用方法?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    varProcessInfo:  TProcessInformation;
    StartUpInfo:  TStartupInfo;
    begin
    FillChar(StartUpInfo,  SizeOf(StartUpInfo),  $00);
    StartUpInfo.dwFlags  :=  STARTF_USESHOWWINDOW;
    StartUpInfo.wShowWindow  :=  SW_SHOWNORMAL;
    if  CreateProcess(nil,  PChar('你的程序.exe'),  nil,  nil,
    False,  IDLE_PRIORITY_CLASS,  nil,  nil,  StartUpInfo,
    ProcessInfo)  then
    begin
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
    end else
      ShowMessage( SysErrorMessage(GetLastError()));
    end;
      

  2.   

    估计是路径的问题。
    ShellExecute的第3个参数是文件名,第4个是附加参数,第5个是路径,
    可能是因为第5个参数设为nil了。
      

  3.   

    汗,还是和以前一样的效果。 因为我调用的程序有很多。有些程序可能加过壳的,
    提示 : Debugger detected - please close it down and restart!
            Windows NT users:Please note that having hte WinIce/SoftIce service installed means that you are running a debugger!
    我直接打开或者用运行打开都没有问题。 我看过别人的程序调用也可以。
      

  4.   

    应该是加壳程序对一般的调用做了保护。 但应该有种方法可以完成调用的。有人的程序做到了,而且windows运行也可以做到。
      

  5.   

    我以下的方法应该可以,只是不知为何 SW_HIDE不能隐藏explorer的提示窗口
    procedure TForm1.Button1Click(Sender: TObject);
    var
    ProcessInfo:  TProcessInformation;
    StartUpInfo:  TStartupInfo;
    t,tb:thandle;
    id:integer;
    begin
    FillChar(StartUpInfo,  SizeOf(StartUpInfo),  $00);
    StartUpInfo.cb:=sizeof(StartUpInfo);
    StartUpInfo.dwFlags  :=  STARTF_USESHOWWINDOW  ;
    StartUpInfo.wShowWindow  :=  SW_HIDE;
    if  CreateProcess(nil,  PChar('explorer.exe "E:\Program Files\DLAB\exe\sygl.exe"'),  nil,  nil,
    False,  0,  nil,  nil,  StartUpInfo,ProcessInfo)  then
    begin
        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ProcessInfo.hProcess);
        Sleep(500);
        t:=findwindow(nil,'文件下载');
        if t=0 then
        begin
          ShowMessage('内部错-1!');
          exit;
        end;
        tb:=findwindowex(t,0,nil,'打开(&O)');
        if tb=0 then
        begin
          ShowMessage('内部错-2!');
          exit;
        end;
      id:=GetDlgCtrlID(tb);
      SendMessage(t,WM_COMMAND, MAKELONG(id,BN_CLICKED),dword(tb));end else
      ShowMessage( SysErrorMessage(GetLastError()));
    end;
      

  6.   

    //生成一个批处理文件来运行var
      vFileName: TFileName;
    begin
      with TStringList.Create do try
        Text := '"' + 'C:\Program Files\Borland\Delphi6\Bin\imagedit.exe' + '"';
    //加上双引号避免路径中有空格的情况
        vFileName := Format('c:\temp%d.bat', [GetTickCount]);
        SaveToFile(vFileName);
        WinExec(PChar(vFileName), SW_HIDE);
        Sleep(500);
        DeleteFile(vFileName);
      finally
        Free;
      end;
    end;
      

  7.   

    我一开始就是用批处理的方法,好像也不行,关键是,它执行时要判父进程为explorer
      

  8.   

    呀对,keiy() 说的很对。 用zswang的方法,遇到用加壳工具加过反调试的程序时还是提示错误。
      

  9.   

    我刚才新建了一个名称为explorer的工程,然后用  
    ShellExecute(Handle, nil, Pchar(strPath), nil, nil, SW_NORMAL);
    为什么还是出错?
      

  10.   

    应该与explorer名字无关,它的父进程要为系统的explorer
      

  11.   

    可以用 hMir := FindWindow('','explorer'); 找到Explorer的句柄
    然后 ShellExecute(hMir, nil, Pchar(strPath), nil, nil, SW_NORMAL);
    打开它吗? 我不知道  FindWindow('','explorer'); 找不到Explorer的句柄,改怎么写才好?
      

  12.   

    估计还是不行,explorer的主窗口为desktop,它的handle应为0
    ShellExecute只会改父窗口,而不会改父进程
      

  13.   

    晕,应该是有办法的呀。 用asprotect加壳后,他是可以运行加壳程序的,我看到过别人的一个程序也可以调用加壳程序的。
      

  14.   

    //    ShellExecute(self.handle, 'open', Pchar('c:\winnt\explorer.exe'+str), nil, nil, SW_SHOW);ShellExecute(handle,'open','mspaint.exe',Pchar('"'+str+'"'),'',SW_MAXIMIZE);//    winexe(
        //ShellExecute(self.Handle,'open',Pchar(str),nil,nil,sw_NORMAL);
      

  15.   

    建议你先认真研究一下这两个函数再想办法:1、WinExec(),2 CreateProcess(); 注意:不是WinExe();
      

  16.   

    兄弟用普通的 WinExec() 和 CreateProcess() 调用方法是无法打开被加壳工具设置过反调试保护的程序的。
    我用 zswang(伴水清清)(专家门诊清洁工) 的方法先生成一个批处理文件依然无法调用,会弹出反调试窗口。但我直接运行该批处理文件,却可以打开。
    我听说过用OD(一种手工脱壳工具)在打开这种加壳程序的时候也回弹出反调试窗口,但他有多种插件可以把OD隐藏起来。这样在调试的时候就不会出错。如HideOD 0.12 。该插件是通过隐藏 用API函数IsDebuggerPresent()的检测来躲过反调试功能的。 有没有办法,可以像这个插件一样让自己的程序躲过IsDebuggerPresent()的检测?
      

  17.   

    晕哦,我用WinExec() 可以,可能是我们这里没有加过客的!