在D7中,执行以下语句:winExec('OSQL /U sa /P aaa',sw_hide);后,我怎么取得该语句的执行结果?如果用户名和密码正确,则系统会进入提示符:
1>如果不正确,系统会进行错误提示!所以在执行完 winExec('OSQL /U sa /P aaa',sw_hide);
后必须取得执行的结果,再根据结果作下一步操作!
我应该怎么取得执行后的结果呢?虽然现在有一种很笨的办法winExec('OSQL /U sa /P aaa >c:\aa.txt',sw_hide);
然后再不断的去解析aa.txt文件!这种方式太笨,太不灵活!各位大侠有没有更好的解决方案呢?

解决方案 »

  1.   

    to : wangzhanlili(小木头)
    能不能进一步提示一下,怎么用管道?
      

  2.   

    var x:cardinal;x:=winexec('rundll32.exe shell32.dll,Control_RunDLL',9);if x=0 then messagebox(0,'程序超出内存','错误',0);
    if x=ERROR_BAD_FORMAT then messagebox(0,'该程序非一个合法的Win32.EXE程序).','错误',0);if x=ERROR_FILE_NOT_FOUND then messagebox(0,'指定文件没找到','错误',0);
    if x=ERROR_PATH_NOT_FOUND then messagebox(0,'指定路径没找到','错误',0);
      

  3.   

    关键是我不需要取得winExec('OSQL /U sa /P aaa‘,sw_hide)这个语句的语法正确情况,
    OSQL /U sa /P aaa 这个语句肯定能正确执行!
    我需要取得的是这个语句的执行结果!
    而不是这个语句的正确性!
      

  4.   

    用管道
    http://search.csdn.net/Expert/topic/1922/1922698.xml?temp=.1852533
    http://search.csdn.net/Expert/topic/1922/1922698.xml?temp=.1852533
    http://search.csdn.net/Expert/topic/732/732724.xml?temp=.9616053
      

  5.   

    The WinExec function runs the specified application. This function is provided for compatibility with earlier versions of Windows. For Win32-based applications, use the CreateProcess function. UINT WinExec(    LPCSTR lpCmdLine, // address of command line 
        UINT uCmdShow  // window style for new application 
       );
     ParameterslpCmdLinePoints to a null-terminated character string that contains the command line (filename plus optional parameters) for the application to be executed. If the name of the executable file in the lpCmdLine parameter does not contain a directory path, Windows searches for the executable file in this sequence: 1. The directory from which the application loaded. 
    2. The current directory. 
    3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory. 
    4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory. 
    5. The directories listed in the PATH environment variable.  uCmdShowSpecifies how a Windows-based application window is to be shown and is used to supply the wShowWindow member of the STARTUPINFO parameter to the CreateProcess function. For a list of the acceptable values, see the description of the nCmdShow parameter of the ShowWindow function. For a non-Windows - based application, the PIF file, if any, for the application determines the window state.  Return ValuesIf the function succeeds, the return value is greater than 31.//注意注意
    If the function fails, the return value is one of the following error values: Value Meaning
    0 The system is out of memory or resources.
    ERROR_BAD_FORMAT The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
    ERROR_FILE_NOT_FOUND The specified file was not found.
    ERROR_PATH_NOT_FOUND The specified path was not found.
      

  6.   

    CreatePipe的方法,Google上能找到组件的http://lysoft.7u7.net