Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inject asm in a .bat header to run itself backgroud?

58 views
Skip to first unread message

est

unread,
Oct 13, 2006, 12:11:04 AM10/13/06
to
.bat files can do many interesting jobs, and easy to use. But under
2k/XP there is a black box splash on the screen if you double click a
.bat file. I just wandered if we can build a ASCII asm code into the
header of .bat and run it like a .com, and the .com can call a Win32
API to re-call itself to run background. This .bat may start with the
charactor : because in cmd.exe intepreter, andy charactor followed by a
: at the start of line is ignored. So can anyone just write that code
for me or give me some clue.

P.S. Is Herbert Kleebauer on this newsgroup?

Herbert Kleebauer

unread,
Oct 13, 2006, 5:30:52 AM10/13/06
to


Why don't you create a shortcut to the batch file and use the "execute
minimized" check box. If you start the batch file with this shortcut,
the command window isn't opened (but you will see it in the task bar).

If you also don't want the entry in the task bar, you can use the
code below. But be careful, if your batch hangs and doesn't make the
window visible itself, I don't know how you can get the window back.

-------------------------------------------------------------------------

showwin.exe let you minimize/maximize/hide the command window
within a batch program (requires W2k or better).

Usage: showwin.exe number


0 SW_HIDE
Hides the window and activates another window.

1 SW_SHOWNORMAL
Activates and displays a window. If the window is minimized or maximized,
the system restores it to its original size and position. An application
should specify this flag when displaying the window for the first time.

2 SW_SHOWMINIMIZED
Activates the window and displays it as a minimized window.

3 SW_MAXIMIZE
Maximizes the specified window.

3 SW_SHOWMAXIMIZED
Activates the window and displays it as a maximized window.

4 SW_SHOWNOACTIVATE
Displays a window in its most recent size and position. This value is
similar to SW_SHOWNORMAL, except the window is not actived.

5 SW_SHOW
Activates the window and displays it in its current size and position.

6 SW_MINIMIZE
Minimizes the specified window and activates the next top-level window
in the Z order.

7 SW_SHOWMINNOACTIVE
Displays the window as a minimized window. This value is similar to
SW_SHOWMINIMIZED, except the window is not activated.

8 SW_SHOWNA
Displays the window in its current size and position. This value is
similar to SW_SHOW, except the window is not activated.

9 SW_RESTORE
Activates and displays the window. If the window is minimized or maximized,
the system restores it to its original size and position. An application
should specify this flag when restoring a minimized window.

10 SW_SHOWDEFAULT
Sets the show state based on the SW_ value specified in the STARTUPINFO
structure passed to the CreateProcess function by the program that
started the application.

11 SW_FORCEMINIMIZE
Windows 2000/XP: Minimizes a window, even if the thread that owns the
window is not responding. This flag should only be used when minimizing
windows from a different thread.


---------------------------------------------------------------------------

A simple example:


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>showwin.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>showwin.com
echo T}{zE~@gwkBG@OEKcUt`E}@mqqBsy?seHBEaPhxr?@zAB`LrPEyoDt@Cj?>>showwin.com
echo pky_jN@QEKpEt@ij?jySjN@REKpEt@jj?jyGjN@SEKkjtlGuNw?p@pjirz>>showwin.com
echo FEvAUSQ?_YLTQ@@?~QCo_F~RDU@?aU?@MQ_AMy1GHs?Gw`LbLK@shM`S_d>>showwin.com
echo bD_nsDddlTr_sPdlnTcnaTv_xP_ngD_rhDhsrT_kkDhrtT_fmDRNCTILk?>>showwin.com
echo staThg_So_rPfnqTl`qTdq_ShtpTrdqThV_Sqrm@ILm?O?cOKFDP?@@?dx>>showwin.com
echo OdFUu?N?_B@J@??KD?HUA?QOGB_QO?F?SCAQO?UDF?UCE?Q_F?DUA?CUB?>>showwin.com
echo OFO?FOS?DUO?IUO?FOW?RU{OWFO?mYU?wdsTeQs@OQ@?QAQ?LUA?_F_og~>>showwin.com
echo UODUO?FOSAFOeAUOyAO_DCSHUOOQO?OCFGuHUOGFO?TUO?DRTTqrQ@kcmS>>showwin.com
echo gFkPFUO?ngRThVvTncmTJFvPMQDTrKDDcmqOFkkDFOSAFOeAUOyAdFFSnB>>showwin.com
echo sT`llTKcmTdmhTFQ@PBsdTrmnTdknTmhVTvncTwDSSOshTbnqTrrdTT~?K>>showwin.com
echo ?OGOQp?o??Gds?wOw?PGAtaCHQvNntQv_w?A?it\=upkNQD??OuQsQG[i?>>showwin.com
echo RwrqosHy?Mjmv\@IuBlpUrHdjNAslF~mH}OKT?U??PT~OL?O?O?i?COT~B>>showwin.com
echo U?OCU?YF0x>>showwin.com

showwin.com>showwin.exe
del showwin.com

dir

:: wait 4 seconds
ping -n 4 localhost >nul

:: hide window
showwin.exe 0

dir /b

:: wait 4 seconds
ping -n 4 localhost >nul

:: show window
showwin.exe 5

:: wait 4 seconds
ping -n 4 localhost >nul

del showwin.exe
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


The source code:

winmain::
jsr.l (GetCommandLine)
; skip program name
eor.l r1,r1 ; not within "" flag
dec.l r0
_20: inc.l r0
cmp.b #0,(r0)
beq.b _10
cmp.b #'"',(r0)
bne.b _30
not.l r1
_30: or.l r1,r1
bne.b _20
cmp.b #' ',(r0)
bne.b _20
inc.l r0

_10: eor.l r5,r5
move.l #5,r4 ; default: SW_SHOW
_50: movu.bl (r0),r1
inc.l r0
or.b r1,r1
beq.b _40
sub.b #'0',r1
bcs.b _50
cmp.b #9,r1
bhi.b _50
mulsq.l #10,r5,r5
add.l r1,r5
eor.l r4,r4
br.b _50
_40: or.l r4,r4
beq.b _60
move.l r4,r5

_60: jsr.l (GetConsoleWindow)

move.l r5,-(sp)
move.l r0,-(sp)
jsr.l (ShowWindow)

moveq.l #0,-(sp)
jsr.l (ExitProcess) ; exit program

est

unread,
Oct 14, 2006, 12:20:33 AM10/14/06
to
Great works Herbert Kleebauer !

Thanks everyone. The code is fantastic.

0 new messages