Jump to content

Run Batch scripts on shutdown


smercer

Recommended Posts

Hi all

I was wondering if there was a way to have scripts run before a windows 98 system is shut down.

The Idea is to delete temp files, delete intenet tempory files, cookies etc, start a registry check program, start the scandisk and when finished, run the disk defragmenter if any files in a partition were modifyed since last boot up.

I have seen batch scripts executed on computers at collage and thought I could do all this.

Could someone please help me here? thanks in addvance!!!

Link to comment
Share on other sites


yeah, sorry. I was thinking xp, I didn't notice the 98 til after I read it again. you have to install poledit in 98 options, but thinking about it I don't remember this option for shutdown. My 98 partition is stripped for gaming, so I don't have it installed anymore either so can't check. someone must make a 3rd party tool for this, it seems like it would be a common task.

Edit: you could try a script to do your tasks then run "rundll.exe user.exe,exitwindows"

Link to comment
Share on other sites

yeah, sorry. I was thinking xp, I didn't notice the 98 til after I read it again. you have to install poledit in 98 options, but thinking about it I don't remember this option for shutdown. My 98 partition is stripped for gaming, so I don't have it installed anymore either so can't check. someone must make a 3rd party tool for this, it seems like it would be a common task.

Edit: you could try a script to do your tasks then run "rundll.exe user.exe,exitwindows"

Thanks...

I wanted to be able to execute it from the start menu and shutdown dialog box. is there a way of doing it like this?

Thanks again.

Link to comment
Share on other sites

The best solution would be a VBScript that launch a BAT or another VBS script , then launch the shutdown the dialog box.

While you move your mouse to the "shut down" button, the script should have had the time to do the task expected.

It's easy to do, but I don't have the codes here, and I don't have the time neither, but i will look for something next weeK.

Stay tuned...

Link to comment
Share on other sites

This script should launch Scandisk, wait 7 minutes, then shutdown the computer.

There is a "yes-no-cancel" button.

It should be possible to launch more apps one after one in the same script.

Copy paste the code in notepad and save it as "MyShutdown.vbs"

Then double-clic on it.

To run the scripts you need maybe Windows Script 5.6. (included in Gape's unofficial service pack)

Please tell me if it works. :hello:

Set WshShell = WScript.CreateObject("WScript.Shell")
 BtnCode = WshShell.Popup("This computer will shut down."_
& vbCrlf & "Before shutting down, Scandisk will check your hard drive."_
& vbCrlf & _
 vbCrlf & "Start ScanDisk before shutting down  --> Clic ""Yes"""_
& vbCrlf & "Don't launch Scandisk --> Clic ""No""" , 30, Title, 3 + 16)  
Select Case BtnCode
    '---no answer
    case -1       WshShell.Popup "ScanDisk will now start. Don't touch the mouse or the keyboard!", 3, Title, 0 + 16
                  WshShell.Run("ScanDisk")
                  WScript.Sleep 1500
                  WshShell.SendKeys("{ENTER}")
                  WScript.Sleep 420000        '-------7 minutes = 420000 ms
                  WshShell.SendKeys("{ENTER}{ENTER}")
                  WScript.Sleep 250
    '---yes
    case 6        WshShell.Popup "ScanDisk will now start. Don't touch the mouse or the keyboard!", 3, Title, 0 + 16
                  WshShell.Run("ScanDisk")
                  WScript.Sleep 1500
                  WshShell.SendKeys("{ENTER}")
                  WScript.Sleep 420000        '-------7 minutes = 420000 ms
                  WshShell.SendKeys("{ENTER}{ENTER}")
                  WScript.Sleep 250
    '---no
    case 7        WshShell.Popup "ScanDisk canceled.", 3, Title, 0
    '---cancel
 case 2        wscript.quit
End Select
WshShell.Run "C:\WINDOWS\RUNDLL32.EXE shell32.dll,SHExitWindowsEx 1", 2, false

Link to comment
Share on other sites

Please tell me if it works.  :hello:

Thanks for that, I will try that tonight after I hop of the internet, as I am still on dial up.

Edit: I tryied it last night and it had an error and did not shutdown. Don't worry about fixing it anyway, as I got my own batch file working. Sorry I forgot to notify you, but I did mention it in other posts and lost track of the posts I had asked help for about it.

By the way if you want the batch file I will attach it.

Link to comment
Share on other sites

Ways to run stuff before Windows 9x/ME [ME needs mfd4life Real DOS patch] shuts down or before it starts up:

1. Add lines to C:\autoexec.bat if appropriate for your programs to run from native MS-DOS.

2. If they need to run from within Windows UI, run them from the RunOnceEx registry key by running a REG or INF file from within a BATch file, which [bATch] can also shut down Windows as last command:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnceEx

3. Get AutoIt v3.1.1 32-bit for Windows 9x/NT4/2000/ME/XP/2003 BASIC-like scripting

language automates Windows + DOS session tasks + software installations,

simulates commands, key presses, mouse movements + clicks, includes script to

executable converter, highly customizable:

http://www.autoitscript.com/autoit3/

Direct download [1.7 MB, free, open source]:

http://www.autoitscript.com/files/autoit3/...it-v3-setup.exe

Hope this helps.

Link to comment
Share on other sites

Edit: I tryied it last night and it had an error and did not shutdown.
Just for curiosity (because I may want to do it for myself too), can you post the error message here?

Here the script have no error but I didn't try it to shutdown.

By the way if you want the batch file I will attach it.

Yes, you can copy-paste the code in the message and frame it with CODE.

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

MDGx

Ways to run stuff before Windows 9x/ME [ME needs mfd4life Real DOS patch]shuts down or before it starts up:

1. Add lines to C:\autoexec.bat if appropriate for your programs to run from native MS-DOS.

Does autoexec.bat do anything before shutdown?

2. If they need to run from within Windows UI, run them from the RunOnceEx registry key by running a REG or INF file from within a BATch file, which [bATch]can also shut down Windows as last command:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnceEx

Could you elaborate?

Seems very complicated what you said.

3. Get AutoIt 

yes, very good stuff. You can also use AutoIt for adding functions to VBS.

Link to comment
Share on other sites

MDGx
Ways to run stuff before Windows 9x/ME [ME needs mfd4life Real DOS patch] shuts down or before it starts up:

1. Add lines to C:\autoexec.bat if appropriate for your programs to run from native MS-DOS.

Does autoexec.bat do anything before shutdown?
2. If they need to run from within Windows UI, run them from the RunOnceEx registry key by running a REG or INF file from within a BATch file, which [bATch]can also shut down Windows as last command:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnceEx

Could you elaborate?

Seems very complicated what you said.

3. Get AutoIt 
yes, very good stuff. You can also use AutoIt for adding functions to VBS.
1. Autoexec.bat [if present] runs every time before Windows UI starts up.

2. The RunOnceEx registry key runs any program you specify [even DOS BATCH files] every time while Windows UI loads, but before other programs/TSRs/processes load/run from "Run" registry keys, WIN.INI "load=xxxxx" or "run=xxxxx" lines or from the Startup folder.

Example: this INF file adds a bunch of RunOnceEx commands which will be executed in the background next time Windows UI will load [CS.INF is part of 98SE2ME = http://www.msfn.org/board/?showtopic=37302 ]:

[Version]
Signature="$CHICAGO$"
[DefaultInstall]
AddReg=R
[R]
HKLM,"Software\Microsoft\Windows\CurrentVersion\RunOnceEx\1","0",2,"%11%\SHDOCVW.DLL|DllRegisterServer"
HKLM,"Software\Microsoft\Windows\CurrentVersion\RunOnceEx\1","1",2,"%11%\SHDOCVW.DLL|DllInstall|i"
HKLM,"Software\Microsoft\Windows\CurrentVersion\RunOnceEx\1","2",2,"%11%\SHELL32.DLL|DllInstall|i"
HKLM,"Software\Microsoft\Windows\CurrentVersion\RunOnceEx\1","3",2,"%11%\SHELL32.DLL|DllRegisterServer"
HKLM,"Software\Microsoft\Windows\CurrentVersion\RunOnceEx\1","4",2,"%11%\WEBVW.DLL|DllRegisterServer"
HKLM,"Software\Microsoft\Windows\CurrentVersion\RunOnceEx\1","5",2,"%11%\BROWSEUI.DLL|DllRegisterServer"
HKLM,"Software\Microsoft\Windows\CurrentVersion\RunOnceEx\1","6",2,"%11%\BROWSEUI.DLL|DllInstall|i"
HKLM,"Software\Microsoft\Windows\CurrentVersion\RunOnceEx\1","7",2,"%11%\MYDOCS.DLL|DllRegisterServer"
[SourceDisksNames]
1=,,0

To add these commands into the registry, run CS.INF from a BATch file:

@echo off
START/W RUNDLL32 %windir%\SYSTEM\ADVPACK.DLL,LaunchINFSection CS.INF,DefaultInstall
cls
exit

3. Indeed, AutoIt is 1 cool app.

Highly customizable, u can run anything, anytime.

4. Another way to run programs after Windows shuts down, is to follow the steps detailed at these pages:

http://www.mdgx.com/last3.htm#DOS2DOS

http://www.mdgx.com/lastweek.htm#MSDOSPROMPT

http://www.mdgx.com/newtip1.htm#DOS

http://www.mdgx.com/98-4.htm#98ATX

in order to be able to exit Windows to native MS-DOS, like I do. :)

Then you need to run Windows from within a batch file, I like to call WIN.BAT [in C:\ root = make sure to add C:\ root to your PATH statement into autoexec.bat or config.sys].

Example [deltemp.bat can contain lines to "clean out" all your TEMP, TMP, MS IE TIF, Cookies, History, Mozilla/Netscape/Opera Cache directories, delete APPLOG folder, scandisk all your fixed drives/partitions, scanreg the registry for errors + repair them, delete specific registry keys, upload keys/values into the registry, etc... use your imagination]:

@echo off
mem/c | find/i "vmm32">nul
if not errorlevel 1 goto end
%winbootdir%\win.com %1 %2 %3
call C:\deltemp.bat
:end
cls
exit

And if at the end of all this u want to shut down your computer, unload NOOFF.COM from memory [if present]:

NoOff v1.4 16-bit DOS TSR prevents computer power off by disabling BIOS ACPI

"soft-off" function forcing Windows 95/OSR2/98/98 SE to exit to native MS-DOS

upon shut down on ATX motherboards:

http://home.arcor.de/g.s/dostools.htm

Direct download [279 B, freeware, right-click to save!]:

http://home.arcor.de/g.s/nooff.com

NOOFF.COM uses 336 Bytes of upper DOS RAM if loaded with LOADHIGH in

AUTOEXEC.BAT (upper memory manager required in CONFIG.SYS).

Does NOT work with Windows ME!

See "WIN98 ATX SHUT DOWN FIX" for details:

http://www.mdgx.com/98-4.htm#98ATX

and then run [from the same batch file] ATXOFF.COM:

http://home.arcor.de/g.s/dostools.htm

or:

WIN.COM /Z

Link to comment
Share on other sites

MDGx

Just to make sure you speak english and not chinese:

in order to be able to exit Windows to native MS-DOS, like I do.

Then you need to run Windows from within a batch file,

Do you mean making a transition to an MS-DOS state between windows tasks end down and the power goes off, or do you mean restarting or sort-of restarting in MS-DOS mode, with a set of batch files?

Then how do run windows "from withion a batch file" if you exited windows?

In my conception, you can run only DOS program in DOS, windows program require windows... or that means that windows is still active somehow...

:unsure:

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...