' =========================================================================== ' Source code: PowerBASIC for DOS ' ' Author: Egbert Zijlema (e.zylema@castel.nl) ' Copyright status: Public Domain ' ' Runs SCANDISK.EXE every month to test your hard disk's integrity. ' How to install: ' 1. Compile it in line with the power of your CPU ' 2. Copy DISKSCAN.EXE to a path-directory (e.g. C:\DOS or C:\) ' 3. Add the following command to your AUTOEXEC.BAT file: diskscan ' What it does: ' On every startup DISKSCAN will check when it has been accessed for the ' last time. When this was (more than) 30 days ago, it will propose you ' to run DOS' SCANDISK (ENTER = yes, Esc = no). DISKSCAN modifies its ' own date stamp (to-day's date = DATE$) for a next 30-days period. ' Related article at: http://www.basicguru.com/zijlema/ ' =========================================================================== $INCLUDE "STAMPINC.TXT" FUNCTION MySelf AS STRING ' This function returns name and location (= full pathname) of the ' active executable file. (Note: in the IDE this is PB.EXE, so compile ' it before running it). For the sake of a clear explanation I wrote ' this function in plain BASIC. An ASM-version (faster!) can be ' obtained from Thomas Gohel's Website at: ' "www.snafu.de/~pbsound/english/index.html" . ' DOS saves the program's environment in the environment block. The ' memory location of this block is stored in the Program Segment ' Prefix (or PSP). Let's find this first: REG 1, &H6200 ' service in AX-register CALL INTERRUPT &H21 PSP = REG(2) ' result in BX-register ' The segment address of the environment block itself is stored in ' offset 2D hex (high) and 2C hex (low) of the PSP DEF SEG = PSP ' load PSP blok = PEEK(&H2D) * 256 + PEEK(&H2C) ' retrieve block segment address DEF SEG = blok ' now load block segment ' The environment block has 2 parts. The first contains information ' set by CONFIG.SYS/AUTOEXEC.BAT. We don't need that here. ' Fortunately the 2 'halfs' of the block are separated by ' 4 bytes, the first 2 being zero. So we simply skip the first ' half by reading it until we find 2 zero bytes on a row. ' Note: 1 INTEGER has a length of 2 bytes. So, we use PEEKI. offset = 0 ' first offset of the segment DO INCR offset ' next offset LOOP UNTIL PEEKI(offset) = 0 ' 2 zeros on a row INCR offset, 4 ' skip 4 separating bytes DO temp$ = temp$ + CHR$(PEEK(offset)) ' character reading INCR offset LOOP UNTIL PEEK(offset) = 0 ' until end of ASCIIZ-string DEF SEG ' restore default segment FUNCTION = temp$ END FUNCTION FUNCTION GetKey AS INTEGER DO LOOP UNTIL INSTAT FUNCTION = CVI(INKEY$ + CHR$(0)) END FUNCTION ' MAIN FileName$ = MySelf ' pathname of running file MakeStampsAvailable FileName$ dStamp?? = REG(4) ' date stamp IF DateToStamp(DATE$) - dStamp?? => 32 THEN ' accessed it (more than) ' 1 month ago? AttachStamps FileName$, _ TimeToStamp(TIME$), _ DateToStamp(DATE$) ' then modify stamp .... ' .... and propose to run SCANDISK: COLOR 7, 0 CLS LOCATE 2, 2 PRINT "It's a month (or more) ago that the integrity of your" LOCATE 3, 2 PRINT "computer's hard disk has been tested by SCANDISK" LOCATE 5, 2 PRINT "Press to run SCANDISK" LOCATE 6, 2 PRINT "Press to skip this monthly procedure" COLOR 15 LOCATE 5, 8 : PRINT "[ENTER]" LOCATE 6, 8 : PRINT "[ESC]" COLOR 7 DO KeyIn = GetKey SELECT CASE KeyIn CASE 27 : EXIT LOOP ' Esc pressed, don't run CASE 13 : EXECUTE "scandisk" ' doit ' note: ' when your (older) DOS-version does not support SCANDISK ' then modify the above line as: EXECUTE "chkdsk /f" END SELECT LOOP END IF END