Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1019 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detect ANSI-compatible console from Windows batch file?

#1
Windows 10 console host, `conhost.exe`, has [native support for ANSI escape sequences][1], older versions do not. How can one detect the presence or absence of console ANSI support from a batch file?

Is it possible to call [`GetConsoleMode`][2] or other Windows API calls directly from a batch file?


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#2
The answer to your last question is: Yes, with the aid of PowerShell code. This Batch file do what you requested:

@echo off
setlocal

set /A STD_OUTPUT_HANDLE=-11
set /A ENABLE_PROCESSED_OUTPUT=1, ENABLE_WRAP_AT_EOL_OUTPUT=2, ENABLE_VIRTUAL_TERMINAL_PROCESSING=4

PowerShell ^
$GetStdHandle = Add-Type 'A' -PassThru -MemberDefinition ' ^
[DllImport(\"Kernel32.dll\")] ^
public static extern IntPtr GetStdHandle(int nStdHandle); ^
'; ^
$GetConsoleMode = Add-Type 'B' -PassThru -MemberDefinition ' ^
[DllImport(\"Kernel32.dll\")] ^
public static extern bool GetConsoleMode(IntPtr hWnd, ref UInt32 lpMode); ^
'; ^
$StdoutHandle = $GetStdHandle::GetStdHandle(%STD_OUTPUT_HANDLE%); ^
$ConsoleMode = New-Object -TypeName UInt32; ^
$null = $GetConsoleMode::GetConsoleMode($StdoutHandle,[ref]$ConsoleMode); ^
Set-Content ConsoleMode.txt $ConsoleMode ^
%End PowerShell%

set /P "ConsoleMode=" < ConsoleMode.txt
set /A "AnsiCompatible=ConsoleMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING"
if %AnsiCompatible% neq 0 (
echo The console is Ansi-compatible!
) else (
echo Ansi codes not supported...
)

I wrote this type of code reading the examples at the PowerShell help on Add-Type cmdlet and the info given in the accepted answer at [this question][1].

[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through