IPB

Google Frontpage Forums Unattended CD/DVD Guide
 Forum Rules Unattended CD/DVD Guide Homepage · MSFN Forum Rules
3 Pages V   1 2 3 >  
Reply to this topicStart new topic
> [Tool] Hide console (command line) windows, run you batch files completely hidden
Vadikan
post Jun 23 2005, 05:56 PM
Post #1


MS MVP Windows Shell/User
***

Group: Members
Posts: 346
Joined: 22-February 04
Member No.: 14702
Country Flag


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
QUOTE
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
CODE
RunHiddenConsole.exe %systemdrive%\install\cleanup.cmd


Runs prepare.cmd hidden and waits until it ends, then runs cleanup.cmd hidden.
CODE
RunHiddenConsole.exe /W %systemdrive%\install\prepare.cmd
RunHiddenConsole.exe %systemdrive%\install\cleanup.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
CODE
cmdow /run /hid batch.cmd
you still see a console window "blinking" for a moment before it gets hidden. When you run
CODE
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 ;-)
CODE
#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

This post has been edited by VAD: Jul 10 2005, 11:01 PM
Attached File(s)
Attached File  RunHiddenConsole.exe ( 1.5K ) Number of downloads: 3096
 
Go to the top of the page
 
+Quote Post
Alanoll
post Jun 23 2005, 10:42 PM
Post #2


CODE tags people, CODE tags!
Group Icon

Group: Patrons
Posts: 5496
Joined: 25-September 03
From: Dallas, Texas
Member No.: 7393
OS: none
Country Flag


Good to see one of them MSFN offshoot sites doing creative things tongue.gif I know you know what I mean VAD (reminds me...the Unattended site should be getting an overhaul shortly).

Oh yeah, this reminds me of this topic: http://www.msfn.org/board/index.php?showtopic=49103

Sounds similar, though I haven't read your entire post nor theirs tongue.gif
Go to the top of the page
 
+Quote Post
Vadikan
post Jun 24 2005, 05:02 PM
Post #3


MS MVP Windows Shell/User
***

Group: Members
Posts: 346
Joined: 22-February 04
Member No.: 14702
Country Flag


Ah, I see, I should've searched better smile.gif However, mods search differently, 'cause they read all topics and often remember the titles or even some posts newwink.gif

You can merge this thread with the one you gave the link to, if you wish.
Go to the top of the page
 
+Quote Post
SiMoNsAyS
post Jun 24 2005, 05:25 PM
Post #4


C'mon you apes! You wanna live forever!?
Group Icon

Group: Patrons
Posts: 3455
Joined: 17-May 04
From: Puertollano, Spain
Member No.: 20147
Country Flag


i think you can use cmdow in a similar way. i.e: "cmdow /hid /run path\file.cmd"...

...not sure... tongue.gif

cool adition anyway smile.gif

edit: after testing, yes, with cmdow you always see a "blinking" command window

This post has been edited by SiMoNsAyS: Jun 24 2005, 05:30 PM
Go to the top of the page
 
+Quote Post
Vadikan
post Jun 24 2005, 05:30 PM
Post #5


MS MVP Windows Shell/User
***

Group: Members
Posts: 346
Joined: 22-February 04
Member No.: 14702
Country Flag


SiMoNsAyS
IMHO, there's a minor difference. I covered it in the first hypothetical question in the first post smile.gif
Go to the top of the page
 
+Quote Post
SiMoNsAyS
post Jun 24 2005, 06:25 PM
Post #6


C'mon you apes! You wanna live forever!?
Group Icon

Group: Patrons
Posts: 3455
Joined: 17-May 04
From: Puertollano, Spain
Member No.: 20147
Country Flag


oh my mistake, i missed that part! tongue.gif
i'll definetly include this tool on my uA smile.gif
Go to the top of the page
 
+Quote Post
n7Epsilon
post Jun 25 2005, 07:04 AM
Post #7


Currently Learning: C#, JavaScript, PHP
**

Group: Members
Posts: 156
Joined: 11-February 05
From: Cairo
Member No.: 43736
OS: XP Pro x86
Country Flag


Hi,
Just a minor problem, RunHiddenConsole.exe doesn't have a switch to wait until completion of batch file execution, so I can't use it in RunOnceEx...

-> Can you implement this, (eg: RunHiddenConsole.exe /WAIT)
Go to the top of the page
 
+Quote Post
Vadikan
post Jun 25 2005, 02:21 PM
Post #8


MS MVP Windows Shell/User
***

Group: Members
Posts: 346
Joined: 22-February 04
Member No.: 14702
Country Flag


ChipCraze23
Well, the utility does what it does newwink.gif No switches available. I can ask the author, but nothing's guaranteed. Consider using the startx utility.

To be honest, I have just one cleanup.cmd in my RunOnceEx routine. Apparently, this is the last file. The first command is shutdown with 60 sec delay, so I have plenty of time to execute the rest of the commands.
Go to the top of the page
 
+Quote Post
smashly
post Jun 26 2005, 01:52 AM
Post #9


Member
**

Group: Members
Posts: 107
Joined: 9-April 05
Member No.: 51267
Country Flag


Nice util , but I still need to work out a few things to use it.

If I run this tool from cmdlines.txt it appears to sorta work and sorta not.

CODE
[COMMANDS]
"REGEDIT /S tweaks.reg"
"rhc.exe daemon.cmd"     <-----Fails this
"rhc.exe RunOnceEx.cmd"  <----- Does this fine , all good
My daemon.cmd works fine without the rhc.exe. It just seems to skip the daemon.cmd alltogether when I use rhc.exe.
Thought it maybe was cause of running daemon.msi from %CDROM%\$OEM$\ not from %SystemDrive%\Install\.
Go to the top of the page
 
+Quote Post
n7Epsilon
post Jun 26 2005, 02:00 AM
Post #10


Currently Learning: C#, JavaScript, PHP
**

Group: Members
Posts: 156
Joined: 11-February 05
From: Cairo
Member No.: 43736
OS: XP Pro x86
Country Flag


I have found a difference between STARTX and RunHiddenConsole,

When you start a batch file hidden using RunHiddenConsole, if the batch file contains CMDOW @ /VIS, the batch file can appear, which can be useful (eg: for user input) after being started completely hidden...

But,
when you start the same batch file using StartX, even if the batch file contains CMDOW @ /VIS, the batch file does NOT appear, so I lose this functionality...

--> That's why I'd like to see RunHiddenConsole.exe /WAIT ...
Go to the top of the page
 
+Quote Post
Vadikan
post Jun 26 2005, 01:14 PM
Post #11


MS MVP Windows Shell/User
***

Group: Members
Posts: 346
Joined: 22-February 04
Member No.: 14702
Country Flag


@smashly
QUOTE
Thought it maybe was cause of running daemon.msi from %CDROM%\$OEM$\
That may be the reason, 'cause your batch file has to set the %CDROM% variable first. Put
CODE
SET CDROM=%~d0
in the beginning of the batch file, if you launch it from cmdlines.txt.

@ChipCraze23
I'm confused. Why do you want to use RHC and display the batch file window? If you want to see the window, don't use any of the hiding utils. Could you please elaborate? Meanwhile, I forwarded your feature request to the author.
Go to the top of the page
 
+Quote Post
n7Epsilon
post Jun 26 2005, 02:18 PM
Post #12


Currently Learning: C#, JavaScript, PHP
**

Group: Members
Posts: 156
Joined: 11-February 05
From: Cairo
Member No.: 43736
OS: XP Pro x86
Country Flag


I want to use this utility to run a long batch file...

A part of this batch file contains processes I want hidden to prevent cancellation..., then when the program requires user input, the batch window appears directly at the user input part of the batch program...

I've already implemented this using CMDOW @ /HID at the beginning of the batch file and CMDOW @ /VIS at the part where I want the program to be displayed but am annoyed at the brief flashing DOS windows...
Go to the top of the page
 
+Quote Post
Vadikan
post Jun 26 2005, 02:35 PM
Post #13


MS MVP Windows Shell/User
***

Group: Members
Posts: 346
Joined: 22-February 04
Member No.: 14702
Country Flag


I see now. Well, although offtopic, but the obvious solution is to split your batch file in two smile.gif Run one hidden, run the other visible.
Go to the top of the page
 
+Quote Post
Vadikan
post Jun 27 2005, 01:28 PM
Post #14


MS MVP Windows Shell/User
***

Group: Members
Posts: 346
Joined: 22-February 04
Member No.: 14702
Country Flag


In response to the popular demand: the /W switch has been added. This is the equivavlent of the /WAIT switch for the START console command in Windows. The switch allows to run a batch file and wait until it ends.

The first post has been updated accordingly. Please, re-download the utility.
Go to the top of the page
 
+Quote Post
eirogge
post Jun 27 2005, 02:05 PM
Post #15


www.eirogge.de
**

Group: Members
Posts: 218
Joined: 7-February 04
From: Germany
Member No.: 13913
OS: XP Pro x86
Country Flag


ty. testing it now.
Go to the top of the page
 
+Quote Post
n7Epsilon
post Jun 28 2005, 02:14 AM
Post #16


Currently Learning: C#, JavaScript, PHP
**

Group: Members
Posts: 156
Joined: 11-February 05
From: Cairo
Member No.: 43736
OS: XP Pro x86
Country Flag


Hello VAD,
Thanks for the PM and for the update, here's an issue:

1. RunHiddenConsole.exe /W only works when invoked from a batch file.

eg: TEST.CMD
CODE
@Echo Off
cls
Echo Testings...
Echo.
cls
Cmdow @ /VIS
Echo.
Echo Test completed.
Echo.
ping localhost > NUL
goto end
:end


-> When you execute RunHiddenConsole.exe /W test.cmd, it immediately returns to the prompt without waiting for the batch file...

-> But when you CALL "RunHiddenConsole.exe /W test.cmd" from another batch file, it does wait for the batch file to end...

-> But what if I want to run a batch program by invoking RunHiddenConsole.exe from within SVCPACK.INF in Windows Setup, it may not work in that case, as SVCPACK.INF is not a batch file...

--> I will test and report the results....

-> But I still wish the /W switch works from the command line....

Anyway thank you to you and the author for this utility....
Go to the top of the page
 
+Quote Post
Vadikan
post Jun 28 2005, 03:19 AM
Post #17


MS MVP Windows Shell/User
***

Group: Members
Posts: 346
Joined: 22-February 04
Member No.: 14702
Country Flag


ChipCraze23
Well, I don't know about that... I just tested it in RunOnceEx routine. I made two cmd files: each one would ping localhost 5 times and write the results into a different text file for each ping. I ran both files from RunOnceEx with /W switch, and although I couldn't really see the whole execution process, I could see the 10 files and their creation time.

The screenshot is attached (first one). As you can see, they are in a perfect time order. Now look at the second screenshot. The same files ran from RunOnceEx, but without the /W switch. Apparently, the files executed at the same time.

You may have a different testing technique, though, but I can't test this utility from svcpack.inf smile.gif Post your results.
Attached File(s)
Attached File  test.png ( 4.05K ) Number of downloads: 19
Attached File  test2.png ( 4.15K ) Number of downloads: 15
 
Go to the top of the page
 
+Quote Post
RogueSpear
post Jun 28 2005, 07:43 AM
Post #18


OS: SimplyMEPIS
Group Icon

Group: Normal Sponsors
Posts: 1529
Joined: 18-September 04
From: Buffalo, NY
Member No.: 31429
OS: none
Country Flag


Here's a batch file I call from DetachedProgram and it works like a charm. I stick 7za.exe and RunHiddenConsole.exe in $OEM$\$$\system32.

CODE
@ECHO OFF
%SystemDrive%
cd \
RunHiddenConsole.exe /W 7za.exe x -y -aoa %SYSTEMDRIVE%\DriverPack*.7z -o"%SYSTEMDRIVE%"
RunHiddenConsole.exe %SYSTEMDRIVE%\SetDevicePath.exe %SYSTEMDRIVE%\D
RunHiddenConsole.exe /W 7za.exe x -y -aoa %SYSTEMDRIVE%\000_AllUsers.7z -o"%ALLUSERSPROFILE%"
RunHiddenConsole.exe /W 7za.exe x -y -aoa %SYSTEMDRIVE%\000_ProgFiles.7z -o"%PROGRAMFILES%"
RunHiddenConsole.exe /W 7za.exe x -y -aoa %SYSTEMDRIVE%\000_WinDir.7z -o"%SYSTEMROOT%"
Del %SYSTEMDRIVE%\*.7z /F /Q


Note that a batch from DetachedProgram is hidden by default so there is no need to use RunHiddenConsole.exe with it and the @ECHO OFF is probably unnecessary as well. Anything running from the script is what can take advantage of RunHiddenConsole.exe. Just wanted to show y'all what I use and that it's tested as working without issue.
Go to the top of the page
 
+Quote Post
Vadikan
post Jun 28 2005, 12:58 PM
Post #19


MS MVP Windows Shell/User
***

Group: Members
Posts: 346
Joined: 22-February 04
Member No.: 14702
Country Flag


The utility has been updated again. I guess no further updates will be neccessary. The utility size reduced to 1 kb, switch /W made case-insensitive, usage window is displayed when run w/o parameters. The author renamed the utility to hidec, and this name is displayed in the usage window. You can choose the name you like. You can re-download the utility from the first post.

Thanks for the report, RogueSpear.
Go to the top of the page
 
+Quote Post
MHz
post Jun 28 2005, 01:17 PM
Post #20


SendToA3X v1.7
*******

Group: Members
Posts: 1601
Joined: 2-August 04
Member No.: 26076
OS: XP Pro x86
Country Flag


Very nice VAD. Will add to my commandline tools. Just ran a test, with a batch file, calling tasklist each minute, for 3 minutes. It works well. CMDOW show the console window as when that command was reached.
Nice work, for just a kb in size.

Thanks VAD.
And thanks to the author. thumbup.gif
Go to the top of the page
 
+Quote Post

Google Frontpage Forums Unattended CD/DVD Guide

3 Pages V   1 2 3 >
Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 




Lo-Fi Version Time is now: 20th November 2009 - 10:53 PM
All trademarks mentioned on this page are the property of their respective owners
MSFN is not affiliated with Microsoft
Copyright © 2001-2009 msfn.org
Privacy Policy