From: pandeng@telepath.com (Steve Schafer (TeamB)) Subject: Re: How do I change the boot record on a diskette? Date: 06 Aug 1998 00:00:00 GMT Message-ID: <35fbcf06.168978058@forums.borland.com> Content-Transfer-Encoding: 7bit References: <35C4C3B2.F424A258@all.net> <35cfdff0.15324402@forums.borland.com> <35C7AAFC.7F627FCF@all.net> <35d27966.81508383@forums.borland.com> <35C8A811.4B04D413@all.net> Content-Type: text/plain; charset=us-ascii Organization: TeamB Mime-Version: 1.0 Reply-To: pandeng@telepath.com Newsgroups: borland.public.delphi.winapi On Wed, 05 Aug 1998 20:44:33 +0200, Anonymous wrote: >I'd like to have both of them. >Because the program will be operating in both WinNT and Win 95/98. Here is sample code for both NT and Win95. In either case, the code reads the boot sector from the floppy in drive A, searches for "press any key" and, if found, replaces it with "pick your ear," and then writes the sector back out to the disk. Use great care with this code, especially the Win95 version; it is extremely easy to trash a disk beyond recovery. for NT: --------8<-------- procedure ModifyBootRecord; var Count: Integer; Buf: String; F: THandle; P: Integer; SS: String; begin F := CreateFile('\\.\A:', GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); SetLength(Buf, 512); SetFilePointer(F, 0, nil, FILE_BEGIN); ReadFile(F, Buf[1], 512, Count, nil); P := Pos('press any key', Buf); if P > 0 then begin SS := 'pick your ear'; Move(SS[1], Buf[P], Length(SS)); SetFilePointer(F, 0, nil, FILE_BEGIN); WriteFile(F, Buf[1], 512, Count, nil); end; CloseHandle(F); end; --------8<-------- for Win95: --------8<-------- type TDiocRegisters = record EBX, EDX, ECX, EAX, EDI, ESI, Flags: DWORD; end; TVWin32CtlCode = (ccNone, ccVWin32IntIoctl, ccVWin32Int25, ccVWin32Int26, ccVWin32Int13); function VWin32(CtlCode: TVWin32CtlCode; var Regs: TDiocRegisters): Boolean; var hDevice: THandle; Count: DWORD; begin hDevice := CreateFile('\\.\VWIN32', 0, 0, nil, 0, FILE_FLAG_DELETE_ON_CLOSE, 0); Result := DeviceIoControl(hDevice, Ord(CtlCode), @Regs, SizeOf(Regs), @Regs, SizeOf(Regs), Count, nil); CloseHandle(hDevice); end; procedure ModifyBootRecord; var Regs: TDiocRegisters; Buf: String; P: Integer; SS: String; begin SetLength(Buf, 512); SS := 'Foo Foo Foo Foo Foo'; Move(SS[1], Buf[1], Length(SS)); // int 25, absolute disk read with Regs do begin EAX := $0000; ECX := $0001; EDX := $0000; EBX := LongInt(@Buf[1]); end; VWin32(ccVWin32Int25, Regs); P := Pos('press any key', Buf); if P > 0 then begin SS := 'pick your ear'; Move(SS[1], Buf[P], Length(SS)); // int 26, absolute disk write with Regs do begin EAX := $0000; ECX := $0001; EDX := $0000; EBX := LongInt(@Buf[1]); end; VWin32(ccVWin32Int26, Regs); end; end; --------8<-------- -Steve