I searched the forum for hid* in titles, but couldn't find anything similar except for cmdow.
Let me introduce a small utility that completely hides console windows. All credit goes to a member of Russian board OSZone.net hasherfrog who wrote the utility exclusively for OSZone.net members and welcomed its sharing with MSFN community. [LOL, that sounds like a huge gift
The utility is attached to the post.
====Changelog======
06/28/05 The utility size reduced to 1 kb, switch /W made case insensitive, usage window is displayed when run w/o parameters.
06/27/05 Added /W switch
=================
Usage
Quote
yourfile can be either a batch file or any command line (console) utility.
/W - (case-insensitive) waits for a batch file or console utility to end
Example of usage:
Runs cleanup.cmd hidden
#include <process.h>
#include <windows.h>
// Отключаем станд. библиотеки
#pragma comment(linker,"/NODEFAULTLIB")
// Объединяем секции кода и данных
#pragma comment(linker,"/MERGE:.rdata=.text")
// Разрешаем запись в секцию кода
#pragma comment(linker,"/SECTION:.text,EWRX")
// Новая точка входа
#pragma comment(linker,"/ENTRY:NewWinMain")
//int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR lpszCmd,int nCmd)
void NewWinMain(void)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
int bWait = 0;
DWORD exitcode = 0;
char stopchar = ' ';
char* lpszCmd = GetCommandLine();
// Определяем символ, который будет символизировать конец имени исполняемого файла
if (lpszCmd[0] == '\"') stopchar = '\"';
// Прокручиваем строку до начала параметров запуска
// "lpszCmd[0] != 0" - более-менее надёжная страховка от выхода за пределы буфера
do { lpszCmd++; } while ((lpszCmd[0] != stopchar) && (lpszCmd[0] != 0));
// Если остались пробелы или табы, пробегаем и мимо них
if (lpszCmd[0] != 0)
{
do { lpszCmd++; }
while ((lpszCmd[0] != 0) && ((lpszCmd[0] == ' ') || (lpszCmd[0] == '\t')));
};
// Выводим сообщение об ошибке, если параметров запуска не оказалось
if (lpszCmd[0] == 0)
{
MessageBox(0, "About:\n\nhidec hides console window of started program & waits (opt.) for its termination\n\nUsage:\n\n\thidec [/w] <filename>\n\nWhere:\n\n/w\twait for program termination\nfilename\texecutable file name", "Error: Incorrect usage", 0);
ExitProcess(0);
};
/* "парсер" :-) */
if ((lpszCmd[0] == '/')&&(((lpszCmd[1])|0x20) == 'w')&&(lpszCmd[2] == ' '))
{
bWait = 1;
lpszCmd += 3;
};
// встаем на первый символ в имени файла для запуска
while ((lpszCmd[0] != 0) && ((lpszCmd[0] == ' ') || (lpszCmd[0] == '\t'))) lpszCmd++;
/* create process with new console */
//нехитрая замена memset(&si,0,sizeof(si)); - кстати, а зачем?
unsigned char *ps = (unsigned char*)&si;
for (unsigned int i = 0; i < sizeof(si); i++) ps[ i ] = 0x00;
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
if( CreateProcess( NULL, lpszCmd,
NULL, NULL, FALSE, CREATE_NEW_CONSOLE,
NULL, NULL, & si, & pi ) )
{
if (bWait) WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
else
exitcode = GetLastError();
/* terminate this */
ExitProcess(exitcode);
}
Q. How do I compile?
A. The author uses Visual C++ Toolkit and this is how he compiles:
cl hidec.cpp /GA /O1 /link /subsystem:windows kernel32.lib advapi32.lib user32.lib
Q. I have more questions!
A. This is what the thread is for. I'll try to answer them, but the author, probably, will not.
Thanks for your attention. I hope at least one person will find the utility useful; otherwise I wasted my [working] time typing the post LOL
Attached File(s)
-
RunHiddenConsole.exe (1.5K)
Number of downloads: 3530
This post has been edited by VAD: 10 July 2005 - 11:01 PM



Help


Back to top









