Computing.Net > Forums > Disk Operating System > Batch files at shutdown - #6781 sequel

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch files at shutdown - #6781 sequel

Reply to Message Icon

Name: tsuji
Date: May 23, 2001 at 15:38:23 Pacific
Comment:

Would like to call special attention to John Lewery and Laurence on their messages at

http://computing.net/dos/wwwboard/forum/6781.html

and on my addition. Sure, comments would be appreciated too.



Sponsored Link
Ads by Google

Response Number 1
Name: Laurence
Date: May 24, 2001 at 02:58:32 Pacific
Reply:

Batfiles: The DOS batch file programming handbook


Here's a batch I've been toying with.
It is chock full of information, so
read carefully.

::reboot98.bat
:: Try this one too:
:: rundll32 krnl386.exe,exitkernel
::
@ECHO off
IF "%1"=="" GOTO closewin
FOR %%n in (0 1 2 4 5 6 8) do IF %1==%%n GOTO run
GOTO help

http://members.aol.com/axcel216/msdos.htm
Windows 95/98/ME Complete MSDOS.SYS Reference

http://support.microsoft.com/support/kb/articles/Q118/5/79.asp
Contents of the Windows Msdos.sys File


You have to edit msdos.sys (mind the read-only attribute) to prevent booting
to GUI. Change "BootGUI=1" to 0 then rename LOGOS.SYS and LOGOW.SYS found in
the windows folder. These are just plain old bitmap files with a different
extension. You may even want to get rid of the splash on boot by placing a
"LOGO=0" in the same section.

...
From earlier posts by Tom Lavedas:
For Win 9x and NT (extracted from article in PC Magazine) ...

Close all programs and prompt you to log on:
rundll32.exe shell32.dll,SHExitWindowsEx

A complete system reboot, use the command line:
rundll32.exe shell32.dll,SHExitWindowsEx 2
rundll.exe user.exe, ExitWindowsExec EW_REBOOTSYSTEM , 0

Power down the system (for laptops):
rundll32.exe shell32.dll,SHExitWindowsEx 5

from other sources ...

rundll32.exe User.exe,ExitWindowsExec 5 % restarts %
rundll32.exe User.exe,ExitWindows % shuts down %

One approach I know of is to Set BootGui=0 in the MSDOS.SYS file, add a 'WIN'
statement to the end of the Autoexec.bat file (create the bat if necessary)
and add a 'MODE co80' line after the WIN statement. Then when the batch or
a shortcut issues the following statement ...

rundll32.exe User.exe,ExitWindows % shuts down %

the system will exit to a pure DOS prompt. It is reported that the system
may not be too stable in this condition, but I have not done any testing
myself.
...

http://support.microsoft.com/support/kb/articles/q234/2/16.asp
How to Exit Windows 98/Me Automatically Using a Batch File

http://support.microsoft.com/support/kb/articles/Q238/0/96.ASP
Problems Shutting Down Windows 98 Second Edition

AFAIK, it was an executable patch. I believe I used this download...
http://www.microsoft.com/windows98/downloads/bin/w98/4756US8.EXE


Is it possible to close Windows (98) and return to DOS?

As in the Win1-3.x days?

Yes, you can:
1. Set BootGUI=0 in MSDOS.SYS. Without this, there is no
shell for Windoze to return to.
2. Run %windir%\system\msconfig.exe. Select Advanced...
Set Disable fast shutdown.

I have Win98SE and this "Disable fast shutdown" option is not there. What
gives?

That's odd. What is the version and file size of your msconfig.exe? Mine is 4.10.1998 and it takes
69,632 bytes.


When you apply the patch, the FastReboot option will be disabled. The patch
also replaces msconfig.exe, and a few other files, so the FastReboot option
will no longer be user accessible. Well, not through msconfig.exe anyway,
but you can still set it active through the registry.


Anyway, this registry hack will probably work just as well:
[HKLM\System\CurrentControlSet\Control\Shutdown]
"FastReboot"="0"

:: untested.bat, but should also work
@echo off
echo FastReboot Menu (for use with Win 98 only!)
echo.
echo 0 - Disable
echo 1 - Enable
echo.
choice /c12 Selection:
if errorlevel 2 set FastReboot=1
if errorlevel 1 set FastReboot=0
if %FastReboot%'==' goto end
echo REGEDIT4>tmp.reg
echo [HKLM\System\CurrentControlSet\Control\Shutdown]>>tmp.reg
echo "FastReboot"="%FastReboot%">>tmp.reg
start /wait regedit tmp.reg
del tmp.reg
:end

You should now be able to return to DOS using the
"Shut Down" command of the Start Menu.

BTW, msconfig.exe from Win98 works in Win95 too.

Alas, if you have an ATX computer, you'll find that
Windows will power down the machine. To prevent this
you will need to beat win.com into shape:

debug %windir%\win.com
-s 100,f000 cd,15

Debug will list a number of addresses where INT 15
instructions were found:
0BE4:1367
0BE4:13A8
0BE4:13B2
[etc.]

Begin disassembly at the first address:
-u 1367
0BE4:1367 CD15 INT 15
0BE4:1369 7303 JNB 136E
0BE4:136B E99C00 JMP 140A
0BE4:136E 81FB4D50 CMP BX,504D
[etc.]

Win.com is looking for APM. Such behaviour is clearly
undesirable, so quell it:
-a 1369
0BE4:1369 nop
0BE4:136A nop
0BE4:136B

Now save your work and return to the command prompt:
-w
Writing 060D7 bytes
-q


Congratulations. You have eliminated a major annoyance
of Win98.

Win95 has the same effect on ATX machines too.


:help
ECHO.
ECHO restart Windows 98/Me automatically:
ECHO.
ECHO runonce.exe -q
ECHO.
ECHO rundll32.exe shell32.dll,SHExitWindowsEx n
ECHO.
ECHO where n is one, or a combination of, the following numbers:
ECHO.
ECHO 0 - LOGOFF
ECHO.
ECHO 1 - SHUTDOWN
ECHO.
ECHO 2 - REBOOT
ECHO.
ECHO 4 - FORCE
ECHO.
ECHO 8 - POWEROFF
ECHO.
PAUSE
ECHO The above options can be combined into one value to achieve
ECHO different results. For example, to restart Windows forcefully,
ECHO without querying any running programs, use the following
ECHO command line:
ECHO.
ECHO rundll32.exe shell32.dll,SHExitWindowsEx 6
ECHO.
ECHO NOTE: Using the FORCE option can cause programs to lose data.
ECHO.
ECHO Below is an explanation of each available option used with the
ECHO above command line:
ECHO.
ECHO 0 - LOGOFF
ECHO Shuts down all running processes, then logs the user off.
ECHO.
ECHO 8 - POWEROFF
ECHO Shuts down the system and turns off the power. The
ECHO system must support the power-off feature.
ECHO.
ECHO 2 - REBOOT
ECHO Shuts down the system and then restarts the system.
ECHO.
PAUSE
ECHO 1 - SHUTDOWN
ECHO Shuts down the system to a point at which it is safe to
ECHO turn off the power. All file buffers have been flushed to disk, and
ECHO all running processes have stopped.
ECHO.
ECHO 4 - FORCE
ECHO Forces processes to terminate. When this flag is set, Windows
ECHO does not query running applications to inform them that Windows is
ECHO shutting down. This can cause the applications to lose data,
ECHO therefore, you should only use this flag in an emergency.
ECHO.
ECHO The "rundll32.exe shell32.dll,SHExitWindowsEx (n)" command mentioned
ECHO above can be called from the RunOnce registry key.
ECHO.
ECHO The runonce.exe -q command mentioned above restarts the computer after
ECHO a 15 second delay. There are no other options when using this command
ECHO line, and it cannot be called from the RunOnce registry key.
ECHO.
PAUSE
ECHO For additional information about the RunOnce registry key, please see
ECHO the following article in the Microsoft Knowledge Base:
ECHO.
ECHO Q137367 Definition of the RunOnce Keys in the Registry
ECHO.
ECHO Additional query words:
ECHO.
ECHO Keywords : win98 kbWinME
ECHO Issue type : kbinfo
ECHO Technology :
GOTO end

:closewin
rundll32.exe User.exe,ExitWindows
GOTO end

:run
rundll32.exe shell32.dll,SHExitWindowsEx %1

:end
ECHO.
::

You will have to sort out the line wrapping.
Man, I hate web-based forums.



0

Response Number 2
Name: tsuji
Date: May 24, 2001 at 03:26:45 Pacific
Reply:

Hello, Laurence. Acknowledge noticing you've posted your informative message above. I would like to look into it. But, for the present, I can't possibly response as I'll be occupied for another 6 hours at least. So I'll probably post back within 24 hours.

Thanks a lot and really appreciate it.


0

Response Number 3
Name: tsuji
Date: May 24, 2001 at 10:02:25 Pacific
Reply:

Let us take thing up here.

First a couple of comments on the batch file you present.

[1] There are some Q&A in your batch which may origin from some pasting from your previous correspondence with someone else, so I am not sure the Q's address to me or to the forum. I take it not.

[2] Though I admire you conceive your batch file as general as possible to cover diverse cases, I don't personally think I will concur with the ambition so manifested. One simple reason is that I would not mix a bug fixing job with a routine job in the same batch file.
[2.1] If ATX is a problem, you fix it once and for all in a dedicated batchfile.
[2.2] If a smooth shutdown is a problem, you fix it the same. Besides, the shutdown problem can be triggered by many reasons, some by 'design bugs' and some by random corruption of cache files etc which occur in time beyond user's control. So believing a universal fixing routine in a batchfile is ludicious.
[2.3] Some lines refer to runonce -q way of doing thing. I don't think it mixes well with administrative job like virus scan, defrag etc. The errorlevel capture is very problematic. I would not recommend it strongly.
[2.4] A forced shutdown or a forced restart can provoke data loss : this is true, in particular on a network config. But, for a network administer who tries to do routine shutdown/restart job, his/her consideration should go well beyond a batch of this kind in an operator-free supervision environment. We won't solve that problem here.

I won't go deep into other aspects. I am sure I have something to learn from, but the mixture of functionality or rather the impurity of functional focus of a batch file bother me a lot.

[3] As to the cmdline rundll32 shell32, the parameter n determines the exact instruction.
N can be decomposed in a unique way in the base of [2^m,2^(m-1),...] with coefficient 0 or 1. Nonzero coefficients on (1,2,4,8) determines the exact instruction, with
0 : logoff (special network concerned)
1 : shutdown
2 : reboot
4 : force
8 : power off
with the combination of them. This is well documented in MSKB. In sum, I don't think one should complicate the matter unnecessarily.

[4] If your MSDOS.sys is not specifically set to boot to command prompt, it is not always a good idea, as far as I am concerned, to start a windows session within autoexec.bat. This is fundamentally wrong, because the boot sequence is then intercepted and never complete. It is too big a price to pay if one wants to exit windows then go directly to real dos. It locks up resources in the background and may probably trigger unpredictable behaviour if things go wrong in the windows session---which is often. If that is the main preoccupation, then I would force a reboot after windows session is complete, even go as far as to replace a replica of msdos.sys to make reboot to commandline automatic, if so desired. But, I would even not recommend that, I am very conservative in this aspect.

I confess my preoccupation must be diametrically different from yours in this aspect, so I have lot of reserves expressed. But this is very biased and each one is entitled to their predilection.

In any case, my posting in #6781 address the specific issue raised there and I wish a scheme to do thing right---neat, clean and under clear control---, nothing more.

Be assured my respect. I remain...


0

Response Number 4
Name: hismastersvoice
Date: May 25, 2001 at 02:15:39 Pacific
Reply:

what is all these replys on about? surly you just,

rename win.com to winsomethingelse.com
(you all know that windows just runs windows as if there was a win line in the autoexec.bat)

create a bat file called win.bat
that calls win.com
and then after win.com exits executes whatever else?


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch files at shutdown - #6781 sequel

Batch files at shutdown www.computing.net/answers/dos/batch-files-at-shutdown/6781.html

Close a batch file www.computing.net/answers/dos/close-a-batch-file/2179.html

edit autoexec from batch file www.computing.net/answers/dos/edit-autoexec-from-batch-file/6415.html