保存、恢复BIOS参数
保存、恢复BIOS参数
所谓系统设置是指用户可以选择并安装的硬件设备信息通常必须以某种形式记录下来,以便
在系统启动时,操作系统能够读取这些信息,明确当前系统的硬件配置和用户对某些参数的
设定,以及用户的某些要求,从而保证微机系统的正常工作。不进行正确的系统设置便不能
使微机高效地工作,甚至不能启动。现今各档次微机把设置程序放在ROM BIOS中,因此称为
BIOS设置程序。在需要进行系统参数设置时,运行该BIOS设置程序,在菜单提示下用户可以
很方便地进行各种参数的设定。设置完毕把设定好的参数保存在由电池供电的CMOS存储器中
,即使掉电,信息也不会丢失。但如遇到病毒、人为操作不当等诸多因素,可能造成某些软
、硬件不能正常工作,带来不必要的损失。为此本人编了一个应用程序,它能把BIOS设置程
序中的正确信息以磁盘文件形式保存下来,相反可随时找出对应的磁盘文件恢复系统设置。
源程序清单如下:
#include "stdio.h"
#include "dos.h"
#include "graphics.h"
#define M 64
void rdcmos(void);
void wrcmos(void);
void tp(void);
int k,i;
FILE *fp;
main()
{
clrscr();
gotoxy(10,5);
puts("Save CMOS Data and Restore CMOS Data program");
puts("\t ========================================");
puts("\t 0--quit ");
puts("\t 1--Save CMOS data to file ");
puts("\t 2--Restore CMOS data from file ");
puts("\t ========================================");
printf("\t\t Input your choice:");
scanf("%d",&k);
switch(k)
{case 0:tp();break;
case 1:rdcmos();break;
case 2:wrcmos();break;
default:puts("\n\t Wrong choice!");
break;}
return 0;
}
void rdcmos(void)
{
char fname[15];
printf("Please input save coms filename\n");
scanf("%s",fname);
fp=fopen(fname,"wb");
for(i=0;i<M;i++)
{outportb(0x70,i);
fputc(inportb(0x71),fp);}
fclose(fp);
printf("CMOS informat has been saved to file %s\n",fname);
}
void wrcmos(void)
{
char fame[15];
printf("Please input restor coms filename\n");
scanf("%s",fame);
fp=fopen(fame,"rb");
if(fp==NULL)
{printf("Can not open %s\n",fame);
exit(0);}
for(i=0;i<M;i++)
{outportb(0x70,i);
outportb(0x71,fgetc(fp));}
fclose(fp);
printf("CMOS informat has been restored from file %s\n",fame);
}
void tp(void)
{
int gdriver,gmode;
gdriver=DETECT;
initgraph(&gdriver,&gmode, "c:\\tc");
setbkcolor(BLUE);
cleardevice();
setfillstyle(1,2);
setcolor(YELLOW);
rectangle(100,100,540,380);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,8);
outtextxy(120,120,"Good bey");
setusercharsize(2,1,4,1);
settextstyle(1,0,0);
outtextxy(150,200,"Good bey");
setcolor(15);
settextstyle(3,0,5);
outtextxy(220,200,"Good bey");
setusercharsize(4,1,1,1);
settextstyle(3,0,0);
outtextxy(180,320,"Good");
getch();
closegraph();
}
以上程序由Turbo C 2.0调试通过。编译后可直接执行。