Jump to content

Possible alternate app for hiding console windows


Leapo

Recommended Posts

I ran across this little gem a couple of days ago, anybody have any experience with it? Looks like it might be a great alternative to nircmd for hiding console windows:

http://www.msfn.org/board/index.php?showtopic=49184

Hi, All!

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 biggrin.gif] In fact, the author didn't have unattended installations in mind, he just wrote an utility in responce to one of the threads. That was me who thought about unattended installations.

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

RunHiddenConsole.exe [/W]<path>yourfile

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

RunHiddenConsole.exe %systemdrive%installcleanup.cmd

Runs prepare.cmd hidden and waits until it ends, then runs cleanup.cmd hidden.

RunHiddenConsole.exe /W %systemdrive%installprepare.cmd
RunHiddenConsole.exe %systemdrive%installcleanup.cmd

Me and the author will give additional info in a form of Questions and Answers.

Q. How is this utility different from cmdow?

A. The only purpose of the utility is to hide the console windows. Unlike cmdow, it doesn't have multiple switches and functions.

When you run

cmdow /run /hid batch.cmd

you still see a console window "blinking" for a moment before it gets hidden. When you run

RunHiddenConsole batch.cmd

you don't see any blinking windows.

cmdow can hide a batch file if you include "cmdow @ /HID" line in the file. You still see a console window blinking, though. RunHiddenConsole doesn't have a similar option.

Q. Do I need to specify the path to the utility?

A. Yes, unless you place it somewhere in PATH (%windir%system32 is a good place)

Q. Can I see the hidden window?

A. Well, didn't you want to hide it? smile.gif You can see it in the Task Manager. If you ran a batch file, that would be CMD.EXE; otherwise, look for the name of your console utility.

Q. Does it work at T-12 (cmdlinest.txt)?

A. It didn't hide the console window for me. The author is aware of the problem, and may come up with something. He didn't intend the utility to be used for unattended installs and in cmdlines.txt in particular.

Q. The utility name is too long, can I rename it?

A. Sure. The author actually renamed it to hidec.

Q. Can I see the source code?

A. Yes (comments in Russian, though ;-)

#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:nnhidec hides console window of started program & waits (opt.) for its terminationnnUsage:nnthidec [/w] <filename>nnWhere:nn/wtwait for program terminationnfilenametexecutable 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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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