A程序调用B程序 B程序如果返回一个值(1或者0)
A程序怎么检测这个值呢!小第写一个安装制作程序,设计到注册码的问题。
安装程序setupbulider.exe
注册码验证程序 project1.exe小第打算这样做在setupbulider.exe
带参调用project1.exe ->winexec(pchar('projec1.exe '+'注册码 '+' 验证码'),sw_hide)注册码验证程序启动后,立刻验证该注册码,如果通过返回1,没通过返回0
可是小第不知道如何返回(返回了setupbulider.exe又如何接收呢),查了好久sdk好象mpi可以用,但搞不清楚

解决方案 »

  1.   

    ////////////////////////////////////////////////////////////////  
    // AppName:  name (including path) of the application  
    // AppArgs:  command line arguments  
    // Wait:     0 = don't wait on application  
    //           >0 = wait until application has finished (maximum in milliseconds)  
    //           <0 = wait until application has started (maximum in milliseconds)  
    // Hide:     True = application runs invisible in the background  
    // ExitCode: exitcode of the application (only avaiable if Wait <> 0)  
    //  
    function STO_ShellExecute(const AppName, AppArgs: String; const Wait: Integer;  
      const Hide: Boolean; var ExitCode: DWORD): Boolean;  
    var  
      myStartupInfo: TStartupInfo;  
      myProcessInfo: TProcessInformation;  
      sAppName: String;  
      iWaitRes: Integer;  
    begin  
      // initialize the startupinfo  
      FillChar(myStartupInfo, SizeOf(TStartupInfo), 0);  
      myStartupInfo.cb := Sizeof(TStartupInfo);  
      myStartupInfo.dwFlags := STARTF_USESHOWWINDOW;  
      if Hide then // hide application  
        myStartupInfo.wShowWindow := SW_HIDE  
      else // show application  
        myStartupInfo.wShowWindow := SW_SHOWNORMAL;   
      // prepare applicationname  
      sAppName := AppName;  
      if (Length(sAppName) > 0) and (sAppName[1] <> '"') then  
        sAppName := '"' + sAppName + '"';   
      // start process  
      ExitCode := 0;  
      Result := CreateProcess(nil, PChar(sAppName + ' ' + AppArgs), nil, nil, False,  
                  NORMAL_PRIORITY_CLASS, nil, PChar(ExtractFilePath(AppName)),  
                  myStartupInfo, myProcessInfo);   
      // could process be started ?  
      if Result then  
      begin  
        // wait on process ?  
        if (Wait <> 0) then  
        begin  
          if (Wait > 0) then // wait until process terminates  
            iWaitRes := WaitForSingleObject(myProcessInfo.hProcess, Wait)  
          else // wait until process has been started  
            iWaitRes := WaitForInputIdle(myProcessInfo.hProcess, Abs(Wait));  
          // timeout reached ?  
          if iWaitRes = WAIT_TIMEOUT then  
          begin  
            Result := False;  
            TerminateProcess(myProcessInfo.hProcess, 1);  
          end;  
          // getexitcode  
          GetExitCodeProcess(myProcessInfo.hProcess, ExitCode);  
        end;  
        CloseHandle(myProcessInfo.hProcess);  
      end;  
    end; 
      

  2.   

    CreateProcess
    GetExitCode應該可返回你要的東西, 但你這樣很不安全, 我覺得, 人家要是替換你的
    >>注册码验证程序 project1.exe
    自己返回呢??
    最好用共享全局內存變量
    or 消息類傳剃
      

  3.   

    一、可以A,B共享一块内存区域,然后如果B执行完了,向这块共享区写入一个值,然后发一条自定的信息通知A,就可以了,
      

  4.   

    正如aiirii(ari-爱的眼睛) 所说,楼主这样做很不安全。
    可以将注册文件做成DLL,当安装时调用该DLL的某个函数进行校验注册,这要安全很多。