*!*
参考一片空白,吹水佬
DECLARE long CreateProcess
IN kernel32 as apiCreateProcess
string@,string@,string@,string@,long,long,string@,string@,string@,string@
DECLARE long CloseHandle
IN kernel32 as apiCloseHandle
long
DECLARE long WaitForSingleObject IN kernel32 as apiWaitForSingleObject long,long
DECLARE long CreateFileW
IN kernel32 as apiCreateFileW
string,long,long,string@,long,long,long
DECLARE long GetFileSize
IN kernel32 as apiGetFileSize
long,long@
DECLARE long CloseHandle
IN kernel32 as apiCloseHandle
long
DECLARE long ReadFile
IN kernel32 as apiReadFile
long,string@,long,long@,string@
DECLARE long WriteFile
IN kernel32 as apiWriteFile
long,string@,long,long@,string@
Declare long CreatePipe
IN kernel32 as apiCreatePipe
Long@,Long@,string@,Long
#define CREATE_NO_WINDOW
0x08000000
#define GENERIC_READ
0x80000000
#define GENERIC_WRITE
0x40000000
#define FILE_SHARE_READ
1
#define FILE_SHARE_WRITE
2
#define FILE_ATTRIBUTE_NORMAL
0x80
#define CREATE_ALWAYS
2
#define OPEN_EXISTING
3
#define INVALID_HANDLE_VALUE
-1
Execmd="ipconfig"
cstr=Docmd(Execmd)
n=ALINES(atemp,cstr,CHR(13)+CHR(10))
FOR i=1 TO n
IF "ipv4" $ LOWER(atemp[i])
?ALLTRIM(STREXTRACT(atemp[i],":",""))
EXIT
ELSE
LOOP
ENDIF
ENDFOR
RETURN
FUNCTION DoCmd(cmd)
LOCAL si, pi,sa,h_read ,h_write,cBuffers,cBuffer,bytes_read
STORE 0 TO m.h_read,m.h_write,m.bytes_read
sa=BINTOC(12,"4rs")+BINTOC(0,"4rs")+BINTOC(1,"4rs")
IF 0==apiCreatePipe(@m.h_read ,@m.h_write ,@sa ,0)
RETURN ""
ENDIF
si = BINTOC(68, "4RS") + REPLICATE(0h00,40)+BINTOC(257,"4RS")+REPLICATE(0h00,12)+BINTOC(m.h_write,"4rs")+REPLICATE(0h00,4)
pi = REPLICATE(0h00, 16)
IF apiCreateProcess(null,cmd,NULL,NULL,1,CREATE_NO_WINDOW,NULL,null,@si,@pi) == 0
apiCloseHandle(m.h_write)
apiCloseHandle(m.h_read)
RETURN ""
ENDIF
LOCAL hProcess, hThread
hProcess = CTOBIN(SUBSTR(pi, 1, 4), "4rs")
hThread
= CTOBIN(SUBSTR(pi, 5, 4), "4rs")
apiCloseHandle(m.h_write)
apiCloseHandle(hProcess)
apiCloseHandle(hThread)
m.cBuffers=""
DO WHILE .t.
m.cBuffer=REPLICATE(CHR(0),2048)
m.bytes_read=0
IF apiReadFile(m.h_read ,@m.cbuffer,2048 ,@m.bytes_read ,0) = 0
EXIT
ELSE
m.cBuffers=m.cBuffers+LEFT(m.cBuffer,m.bytes_read)
ENDIF
ENDDO
apiCloseHandle(m.h_read)
RETURN m.cBuffers
ENDFUNC