Jump to content

Batch File hiding


Recommended Posts

Hi,

I have an unattended windows installation. In this I have a CMD file that runs from winnt.sif (GuiRunOnce). Now it works perfectly, but it shows the user what it is doing. What i want is it still to show the CMD window, but have no text displayed within it.

Is this possibke, and if it is, how would I go about doing it?

thanks

HougTimo

Link to comment
Share on other sites


You can hide batchfiles (.cmd or .bat) completely by using HIDE.EXE or BATCHRUNNER.EXE

batchrunner you can find on msfn, there is a topic....

hide.exe... perhaps google.

I use hide.exe for a batchfile, the final thing the batchfile does is start a PDFfile, nice thing is, the batchfile is completely hidden because of hide.exe, but the pdf file is shown. exactly what I wanted.

I'm not sure if this is what you mean.

Link to comment
Share on other sites

i prefer to use cmdow.exe

just put it into \$OEM$\$$\System32

the first string in your .cmd should be "cmdow @ /hid" and you wont c the current command window anymore.

i know u want to c the .cmd window but with no text in it, so perhaps you try to play around with cmdow.

CMDOW [Version 1.4.2]Win32 Commandline Window Utility for NT4/W2K/XP.

© Copyright 2001-2002 Ritchie Lawrence, http://www.commandline.co.uk.

CMDOW [window | /T] [/F] [/P]

CMDOW /TH | /TV | /MA | /CW | /UW | /AT | /FS | /WM

CMDOW window {[/ACT] [/iNA] [/ENA] [/DIS] [/VIS] [/HID] [/MIN] [/MAX] [/RES]

[/TOP] [/NOT] [/REN caption] [/MOV left top] [/sIZ width height] [/CLS]

[/END]}

CMDOW /RUN [state] file [args]

window List specified window (if omitted, all windows are listed).

/T List windows only shown on the taskbar.

/B List windows using bare format (no heading information).

/F List windows showing full information (don't truncate any fields).

/P List windows showing position and size (left, top, width and height).

/TH Tile windows horizontally. /TV Tile windows vertically.

/MA Minimize all windows. /CW Cascade windows.

/UW Undo tile/minimize/cascade. /AT Intelligent [Alt]-[Tab]

/FS Switch to full screen mode. /WM Switch to window mode.

/ACT Activate specified window. /INA Inactivate specified window.

/ENA Enable specified window. /DIS Disable specified window.

/VIS Unhide specified window. /HID Hide specified window.

/MIN Minimize specified window. /MAX Maximize specified window.

/RES Restore specified window. /REN Rename specified window.

/TOP Make window always on top. /NOT Make window not always on top.

/MOV Move specified window. /SIZ Resize specified window.

/CLS Close specified window. /END Kill process linked to window.

/RUN Executes or opens specified file using associated application.

state Initial show state of window (/MIN, /MAX or /HID). Default is normal.

args Optional commandline arguments passed to launched application.

Specify a window by its caption (case insensitive) or handle in hex format.

The At symbol '@' may be used to refer to this window. For more help on any

parameter use CMDOW /? <parameter>. Eg CMDOW /? /RUN or CMDOW /? window.

Edited by myno
Link to comment
Share on other sites

You can use a VBS script to hide the batch

Example

After the batch has completed it will display a message box that will close it self in 7 seconds.

Const Hidden = 0,Normal = 1,Min = 2 
Dim Act
Set Act = CreateObject("Wscript.Shell")
Act.Run("PLACE_YOUR_BATCH_FILE_HERE"),Hidden,True
Act.Popup "Completed the script", 7, 0 + 32, "Finished Script"

Link to comment
Share on other sites

CMDOW canNOT hide the batchwindow completely, you will see a black window flashing!

Personally, I find it an ugly solution. Hide.exe hides it completely, no need to add code or use VBS (some people remove VBS with Nlite).

I couldn't find the official website or topic, but here is HIDE.EXE

use hide.exe /? to see the options.

dito for BATCHRUNNER.EXE

use batchrunner.exe /? to see the options.

But I would recommend HIDE.EXE

Link to comment
Share on other sites

Here is the advantage of using a VBS, you do not have to relay on 3rd party programs. The script I posted will hide the cmd window completly. No flashes

Example script

Save As Hide_HideWindowComSpec.vbs

Const Hide = 0, Norm = 1, Min = 2, Max =3 : Dim Act, CMD1,Fso, Ts, SD, VBSVBS ="\HideWindowComSpec.vbs" : CMD1 = "\TestHideCmd.Cmd" '''' VARIBLES FOR THE SCRIPTSet Act = CreateObject("Wscript.Shell") '''' OBJECT FOR THE SCRIPTSet Fso = CreateObject("Scripting.FileSystemObject") '''' OBJECT FOR THE SCRIPTSet Ts = Fso.CreateTextFile(SD & CMD1) '''' THIS BUILD THE CMD TO RUN THEN THE CMD BUILDS THE TEXT FILESD = Act.ExpandEnvironmentStrings("%Systemdrive%") '''' SET THE SYSTEM DRIVE TO SD'''' WRITE THE CMD THEN RUNS ITTs.WriteLine "@Echo Off" & vbCrLf & "set D=%Date%" & vbCrLf & "Echo The Date : %D% > MyTextTest.txt" &_"&& Echo User Name : %UserName% >> MyTextTest.txt && Echo Windows Dir : %Windir% >> MyTextTest.txt"Ts.Close'''' STARTS THE RUN AND DELETE PHAZEAct.Run(SD & CMD1),Hide,True '''' RUNS THE CMD HIDDENAct.Run("MyTextTest.txt"),Norm,True '''' RUN THE TEXT FILE MADE BY THE CMDFso.DeleteFile(SD & CMD1) '''' DELETES THE FILESFso.DeleteFile("MyTextTest.txt") '''' DELETES THE FILESIf Fso.FileExists(SD & VBS) Then '''' CHECKS THEN DELETE THIS FILEFso.DeleteFile(SD & VBS)End If
Here is a SFX file that will run the above VBS script

I Gunsmokingman give all users full permission to do what ever they want with this script.

HideWindowComSpec.exe

Link to comment
Share on other sites

Most of the time I think we tend to get a little scared of VBScript. If we only need to run a quick command hidden we can meet it half way, remove all the set and dim and const bulk and just invoke a vbs using more familiar batch type coding.

Here is an example, it will run the command completely hidden, it will count for 10 seconds and create a directory in the current location called testdir

CmdLine="ping -n 11 localhost>nul &&MD testdir"
CreateObject("WScript.Shell").run "%comspec% /c " &CmdLine,0,True

Link to comment
Share on other sites

Most of the time I think we tend to get a little scared of VBScript. If we only need to run a quick command hidden we can meet it half way, remove all the set and dim and const bulk and just invoke a vbs using more familiar batch type coding.

Here is an example, it will run the command completely hidden, it will count for 10 seconds and create a directory in the current location called testdir

CmdLine="ping -n 11 localhost>nul &&MD testdir"
CreateObject("WScript.Shell").run "%comspec% /c " &CmdLine,0,True

I only put in that in as a force of habit.

This is the same script as Yzöwl, but I have added a open the folder then it waits for you to close the folder then it deletes the folder.

CreateObject("WScript.Shell").run "%comspec% /c " &CmdLine,0,True

CreateObject("WScript.Shell").run("explorer.exe " & CreateObject("WScript.Shell").CurrentDirectory & "\testdir"),1,True

CreateObject("Scripting.FileSystemObject").DeleteFolder(CreateObject("WScript.Shell").CurrentDirectory & "\testdir")

Link to comment
Share on other sites

What i want is it still to show the CMD window, but have no text displayed within it.

wow he dosent need all of that stuff this can be achived with a simple

echo off

then when you want to display text just use echo "text"

if you want it to show the commands again then just do echo on.

Link to comment
Share on other sites

Most of the time I think we tend to get a little scared of VBScript.
That's very true!

Specially when displayed as a dense blue text like in the code/quote boxes of this forum.

That's a pitty there is no color coding for the main languages used here.

Something like [code type=vbs] tags.

Anyway, I loved (and understood!) your simple 2 lines example. I may try VBS one day... :)

...When I will have forgotten a bit how frustrating its sibling VBA is. :(

Anyway, spazmire11 has the right answer to the original question, I guess.

wow he dosent need all of that stuff this can be achived with a simple echo off
Edited by Djé
Link to comment
Share on other sites

Technically no, what is actually required for the original question is to run the batch file with stderr and stdout redirected

mybatch.cmd >nul 2>&1

There may be a problem with this syntax however from GuiRunOnce in winnt.sif.

Link to comment
Share on other sites

I know it's not relevent anymore since everyone misunderstood the real question and the good answer must be the one from Yzöwl about >nul (with echo off).

But about hiding command prompt window without using 3rd party program or VBScript there is one more solution I don't remember having see in other topics.

TEST.INF

[Version]
Signature="$Windows NT$"
AdvancedINF=2.5

[DefaultInstall]
RunPostSetupCommands=DefaultInstall.RunPostSetupCommands:1

[DefaultInstall.RunPostSetupCommands]
TEST.CMD

And you call it like this

rundll32.exe advpack.dll,LaunchINFSection TEST.INF,DefaultInstall

Edited by jdoe
Link to comment
Share on other sites

Technically no, what is actually required for the original question is to run the batch file with stderr and stdout redirected
mybatch.cmd >nul 2>&1

There may be a problem with this syntax however from GuiRunOnce in winnt.sif.

Yes, after posting, I just remembered one of your posts showing the >nul for stdout, although it was for each individual command.

What is that 2>&1 doing for stderr ?:unsure:?

And maybe hougtimo doesn't want that level of nudity (that is really bare bone) and would appreciate a few veils of echo to tell what's going on? but that's just a conjecture.

rundll32.exe advpack.dll,LaunchINFSection TEST.INF

Hey, jdoe, you seems to know a lot about that advanced inf syntax. Do you have some link to good documentation about it?

Last time I could not manage to register/unregister dlls using that advpack.dll,LaunchINFSection stuff.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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