Jump to content

Getting PID of new created process

Recommended Posts

Hey guys, I am tyring to send commands (using controlsend) to a window that is being created by the cmd window. The cmd window gets a command to open up telnet, from there, I am unable to send anything to the telnet(executbale) window. I have working code that uses the PID of the process to send input back to the window which it was prompted for (It works on the cmd window using it's PID). I tired using the window title and WinGetProcess to get the Pid of telnet, but the result is -1. 

$TPid = WinGetProcess("telnet msn-devqa")


 Any ideas guys? Thanks in advance.


EDIT: I am using control send because the cmd window(and telnet) will prompt the user for something (username or password) and I need to send it back to the cmd window.

Edited by Chance1

Share this post

Link to post
Share on other sites

Moved to the appropriate forum, as the DEV forum very clearly states:


Do not create AutoIt-related topics here, use AutoIt General Help and Support


Edited by JLogan3o13

Share this post

Link to post
Share on other sites

From ControlSend's documentation:


ControlSend() is only unreliable for command prompts as that works differently to normal windows (seems to check physical states rather than accepting the keystroke messages).

ControlSend won't work for CMD

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)


My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!



Share this post

Link to post
Share on other sites

I am using:

StdinWrite($Pid, "...")

to write to cmd, but after the execution of some of the commands, cmd prompts the user to input data. I know when the cmd window will prompt the  user so, for the users response I use the following function:

Func OutputPrompt($input, $ppid)
    $winhandle = 0
    $WindowList = WinList()
    For $i = 1 to $WindowList[0][0] ;loop to find the handle of the cmd window for the PID
        If WinGetProcess($WindowList[$i][1])= $ppid Then
            $winhandle=$WindowList[$i][1]  ;set the handle
    Next ;loop on for loop

    If $winhandle = 0 Then ;handle wasn't found --exit script
        MsgBox(0, "EXIT", "CRITICAL ERROR: HANDLE NOT FOUND - Terminating Script", 2000)
    ;output token to cmd window
    ControlSend($winhandle, "", '', $input  & "{ENTER}")


which I know works everytime.

So, as you can see in the function above, I use the pid of the window to which I am writting to too properly answer the prompted questions. The issue is, one of the commands issued in my script crates a new window and I am unable to get the pid of that new window. Because I cannot get the pid of the new window correctly, I am unable to output to it at all.

Does anyone have an idea of how to get the pid of the new window created? As stated earlier, I know what the title of the new window will be, but WinGetProcess returns -1 for the pid. Thanks in advance.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...