Jump to content
Sign in to follow this  

WinGetHandle for parent console

Recommended Posts

Good Morning,

I am having a small issue in getting the handle for the console window that launched the process - which then tries to get its own handle.

If i may elaborate.

I have a script compiled as a console app. When run, i need to write commands directly back into the command window that launched the exe.

There may be numerous cmd windows open, so looking for a class wouldnt be enough. The command prompt could be launched from desktop or system32 so title wont be enough either.

So what i am asking is, is it possible to get the hwnd for the command prompt window that launched the script ?

My code is as follows :

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <WinAPI.au3>

; validate parameters
; if no parmeters, assume launched via desktop and open GUI exe
; if 1 paramater, assume lanched from cmd line and return error for insuficient parameters
; if 2 paramters, use this info and launch console procedure

if $CmdLine[0] = 0 Then

;launch gui and terminate launcher
Run("C:\GuiPart.exe", "", @SW_MAXIMIZE)

if $CmdLine[0] = 1 Then
; generate console error and terminate
ConsoleWrite ("")
ConsoleWrite ("Error - command not specified")
ConsoleWrite ("")


if $CmdLine[0] = 2 Then
; valid parameters passed - start console process
$tillno = $CmdLine[1]
$cmd = $CmdLine[2]
ConsoleWrite ("")
ConsoleWrite ("Here we go")
ConsoleWrite ("")
ConsoleWrite ("")

;; ^^^^ all working fine above

; get hwnd and write commands to it.
Local $hWnd = WinGetHandle("[CLASS:ConsoleWindowClass]")
Local $sHWND = String($hWnd)    ; Convert to a string

_WinAPI_PostMessage($hWnd, "dir c:\" & @CRLF)


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...