hipfzwirgel Posted September 25 Share Posted September 25 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 More sharing options...
Solution Nine Posted September 29 Solution Share Posted September 29 (edited) You need to allocate new console to make it work like you intend to. But you can hack with something like this : expandcollapse popup#include <WinAPIProc.au3> #include <WinAPISys.au3> #include <WinAPIConstants.au3> #include <WindowsConstants.au3> Global $iResp, $hKBHook If Not @Compiled Then Exit MsgBox($MB_OK, "Error", "This script needs to be compiled") Main() Func Main() _WinAPI_AttachConsole() Local $hConsoleOut = _WinAPI_GetStdHandle(1) Local $sMessage = "Enter [y] for deactivating ML-option or [n] for cancel:" & @CRLF _WinAPI_WriteConsole($hConsoleOut, $sMessage) Local $hKBProc = DllCallbackRegister(KeyProc, "long", "int;wparam;lparam") $hKBHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hKBProc), _WinAPI_GetModuleHandle(0)) While Sleep(100) Switch $iResp Case 1, 2 ;MsgBox($MB_OK, "", $iResp = 1 ? "No" : "Yes") _WinAPI_WriteConsole($hConsoleOut, $iResp = 1 ? "No" : "Yes") Send("{ENTER}") ContinueCase Case 3 ExitLoop EndSwitch WEnd _WinAPI_UnhookWindowsHookEx($hKBHook) DllCallbackFree($hKBProc) EndFunc ;==>Main Func KeyProc($nCode, $wParam, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hKBHook, $nCode, $wParam, $lParam) Local $tKeyHook = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $wParam = $WM_KEYDOWN Then Switch $tKeyHook.vkCode Case 0x59, 0x4E ; y / n $iResp = $tKeyHook.vkCode = 0x4E ? 1 : 2 Return 1 Case 0x0D $iResp = 3 Case Else Return 1 EndSwitch EndIf Return _WinAPI_CallNextHookEx($hKBHook, $nCode, $wParam, $lParam) EndFunc ;==>KeyProc Edited September 29 by Nine better code Zedna 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
hipfzwirgel Posted October 10 Author Share Posted October 10 Hello Nine, first of all please excuse my very late feedback. I'm really sorry about. Your suggestion works very well 👍👍👍👍 Thanks for that. I hope that your help will be rewarded with perpetual summer weather and exuberant wealth. 🤣 🤞🤞 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now