Jump to content

interaction of my Gui-compiled exe with a CMD


hipfzwirgel
 Share

Recommended Posts

Hello folks,

My program is compiled as an exe and can be started both via the GUI version and in a command prompt with command line parameters.

Now a bios option (Minimal lenght) prevents the deletion of the bios password. The user should therefore
be able to confirm at console level that the program should deactivate this option and then reboot the computer.

The status of my coding is that after the user input on WinApi question, an error appears,

I understand why. The input interacts with the console and not with the executed program. Unfortunately
no solution for this. I have already tested an input box, but it looks really bad...

unfortunately when the user do the input y then the error-message 'y' is not recognized as an internal or external command, operable program or batch file appears.
afterwards clicking enter the prompt appears and when i do then the input y it works.

Is it possible to get the Input right from the Cmd so that the shell doesn't start to proceed it?

; Attach console of the parent process
Local $iResult = DllCall("Kernel32.dll", "bool", "AttachConsole", "dword", -1)
_DebugArrayDisplay($iResult, "title")

Local $hConsoleOutput = _WinAPI_GetStdHandle(1)
Local $hConsoleinput = _WinAPI_GetStdHandle(0)

; Set the console mode to control the input

Local $iMode = 0x0004 + 0x0002
DllCall("Kernel32.dll", "bool", "SetConsoleMode", "handle", $hConsoleinput, "dword", $iMode)

; Create buffer to save the input
Local $tBuffer = DllStructCreate("wchar[256]")  ; Buffer für 256 Zeichen

Local $dwCharsRead = DllStructCreate("dword")   ; Anzahl der gelesenen Zeichen

; Forcing console output
Local $sMessage = " Enter [y] for deactivating ML-option or [n] for cancel:" & @CRLF
_WinAPI_WriteConsole($hConsoleOutput, $sMessage)

; Read user input via the WinAPI function ReadConsole / <== This doesn't Work because the input is processed by the CMD and not by the program !!!!

DllCall("Kernel32.dll", "bool", "ReadConsoleW", "handle", $hConsoleinput, "ptr", DllStructGetPtr($tBuffer), "dword", 256, "ptr", DllStructGetPtr($dwCharsRead), "ptr", 0)

Local $iCharsRead = DllStructGetData($dwCharsRead, 1)

Local $sInput = DllStructGetData($tBuffer, 1)
$sInput = StringLeft($sInput, $iCharsRead - 2)  ; Entferne das abschließende CRLF

MsgBox(0, "ausgabe Input", $sInput)

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...