hi, i was wondering...
in the windows program cmd.exe you can of course type many commands
is there a windows API that i can use to send the same commands from a program and possibly recieve the response?
venom_zx
By "response" are you talking about the text output or the return codes?
you can do it using pipes..
create some pipes, set the std handles of the cmd process in the createprocess structure to the pipe handles
@thomas_remkus:
yes i want the text response
@evlncrn8:
thanks . ill try to do it that way :U
I needed the same thing for a program I am writing.
I got the code from Ketilo's RadAsm source code.
I just made some changes.
Here is the code :
MAKE STRUCT
hWnd HWND ?
dwMsgID DWord ?
lpszApplicationName LPSTR ?
lpszCommandLine LPSTR ?
lpszCurrentDirectory LPSTR ?
lpszResultBuffer LPSTR ?
MAKE ENDS
LPMAKE TYPEDEF PTR MAKE
Build_Thread PROC USES EBX EDI ESI,__lpMake:Ptr MAKE
LOCAL _hWrite:HANDLE
LOCAL _hRead:HANDLE
LOCAL _Pi:PROCESS_INFORMATION
LOCAL _Si:STARTUPINFO
LOCAL _Sat:SECURITY_ATTRIBUTES
; ===> Clear Structures
xor eax,eax
lea edi,_Pi
mov ecx,(SIZEOF PROCESS_INFORMATION) / (SIZEOF DWord)
rep stosd
lea edi,_Si
xor eax,eax
mov ecx,(SIZEOF STARTUPINFO) / (SIZEOF DWord)
rep stosd
mov esi,__lpMake
; ===> Init Process
mov _Sat.nLength,SIZEOF SECURITY_ATTRIBUTES
mov _Sat.lpSecurityDescriptor,NULL
mov _Sat.bInheritHandle,TRUE
INVOKE CreatePipe,ADDR _hRead,ADDR _hWrite,ADDR _Sat,NULL
test eax,eax
jz @Exit
mov _Si.cb,SIZEOF STARTUPINFO
INVOKE GetStartupInfo,ADDR _Si
mov eax,_hWrite
mov _Si.hStdOutput,eax
mov _Si.hStdError,eax
mov _Si.dwFlags,STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES
mov _Si.wShowWindow,SW_SHOWNORMAL
; ===> Execute Process
INVOKE CreateProcess,(MAKE Ptr [esi]).lpszApplicationName,(MAKE Ptr [esi]).lpszCommandLine,NULL,NULL,TRUE,NULL,NULL,(MAKE Ptr [esi]).lpszCurrentDirectory,ADDR _Si,ADDR _Pi
test eax,eax
jz @Error_1
INVOKE WaitForSingleObject,_Pi.hProcess,INFINITE
INVOKE GetFileSize,_hRead,NULL
test eax,eax
jz @Error_2
mov edi,eax
INVOKE M_Alloc,eax
test eax,eax
jz @Error_2
mov (MAKE Ptr [esi]).lpszResultBuffer,eax
INVOKE File_Read,_hRead,eax,edi
INVOKE CloseHandle,_hRead
INVOKE CloseHandle,_hWrite
INVOKE CloseHandle,_Pi.hProcess
INVOKE CloseHandle,_Pi.hThread
push (MAKE Ptr [esi]).lpszResultBuffer
push (MAKE Ptr [esi]).dwMsgID
push WM_COMMAND
push (MAKE Ptr [esi]).hWnd
push OFFSET @Exit
jmp PostMessage
; ________________________________________________________________________________
@Error_2 :
INVOKE CloseHandle,_Pi.hProcess
INVOKE CloseHandle,_Pi.hThread
@Error_1 :
INVOKE CloseHandle,_hRead
INVOKE CloseHandle,_hWrite
@Error :
mov (MAKE Ptr [esi]).lpszResultBuffer,NULL
INVOKE PostMessage,(MAKE Ptr [esi]).hWnd,WM_COMMAND,(MAKE Ptr [esi]).dwMsgID,NULL
; ________________________________________________________________________________
@Exit :
INVOKE ExitThread,241259h
ret
Build_Thread ENDP
; ________________________________________________________________________________
Thanks to Ketilo for giving his source code.
I think he will recognize his own code.
The idea of this code is to launch an MS-Dos program and to route the standard output to a file for analyzing it later. The re-routing is made using "CreatePipe" which gives the new requested handles.
Once it is made, we set these handles into the STARTUPINFOS structure which will be passed to "CreateProcess".
Once the process is ended the standard output is read into a new buffer. The new buffer is got with a call to M_Alloc (in fact a VirtualAlloc call). This buffer is then passed as a parameter to a WM_COMMAND message. Like this the window which launched the process knows when it finished and what it did.
OK ?
hi
here is an alternative to the command prompt by akyprian
it´s very nice and use pipe
greets ragdog
[attachment deleted by admin]