Results 1 to 13 of 13

Thread: sending text to cmd.exe?

Hybrid View

  1. #1
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286

    Re: sending text to cmd.exe?

    Quote Originally Posted by RobDog888
    So SendMessage will only work if you create the pipe first? I know it doesnt work directly by getting the CMD window handles.
    You shouldn't have to bring pipes into it

    The following works for me
    VB Code:
    1. Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    2. Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    3. Private Const WM_CHAR As Long = &H102
    4.  
    5. Private Sub Command1_Click()
    6.  
    7.     Dim h As Long
    8.    
    9.     h = FindWindowEx(0, 0, "ConsoleWindowClass", vbNullString)
    10.     If h Then PostMessage h, WM_CHAR, Asc("a"), 0
    11.  
    12. End Sub

  2. #2
    Hyperactive Member Datacide's Avatar
    Join Date
    Jun 2005
    Posts
    309

    Re: sending text to cmd.exe?

    What's wrong with doing it this way?
    VB Code:
    1. Private Sub cmdSendCommand_Click()
    2.   Shell(txtCommand.text)
    3. End Sub
    PHP in your FACE!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width