Adding Path Program
Everyone often finds that some software modifies the AUTOEXEC.BAT file during installation, making the PATH point to its own directory. This article provides a small program that can complete this function. This program can be used directly: ADAPT path name, or the function addpath() can be used in your own installation program.
This program was compiled and passed under Turbo C 2.0 and works normally on X86 compatible machines.
Attached is the source program ADAPT.C
1 #include
2 #include
3 #include
4 #define flag1 "set path="
5 #define flag2 "path="
6 #define endchar(s) (((char *)s))
7 main(int argc,char *argv)
8 { if(argc<2)
9 {printf("Usage: ADPATH newpath\n"
;exit(1);}
10 addpath(argv);}
11 addpath(char *newpath)
12 {FILE *aut,*tmp;
13 char buffer;
14 char tname;
15 tmpnam(tname);
16 if((aut=fopen("c:\\autoexec.bat", "r"
)==NULL)
17 {printf("erro open autoexec.bat"
;exit(1);}
18 if((tmp=fopen(tname, "w"
)==NULL)
19 {printf("error create tmpfile"
;exit(1);}
20 while (!feof(aut))
21 {strcpy(buffer,""
;
22 fgets(buffer, 256, aut);
23 if((strnicmp(buffer, flag1, strlen(flag1))==0) ||(strnicmp(buffer, flag2, strlen(flag2)))==0)
24 {if(endchar(buffer)=='\n'
endchar(buffer) ='\0';
25 strcat(buffer, (endchar(buffer)==';' ? "" : ";"
);
26 strcat(strcat(buffer, newpath), "\n"
;
27 }fputs(buffer,tmp);
28 }fclose(aut);
29 fclose(tmp);
30 remove("c:\\autoexec.bat"
;
31 rename(tname,"autoexec.new"
;
32 system("copy autoexec.new c:\\autoexec.bat"
;
33 remove("autoexec.new"
;
34 }
□Shandong Xu Zhenhua
Everyone often finds that some software modifies the AUTOEXEC.BAT file during installation, making the PATH point to its own directory. This article provides a small program that can complete this function. This program can be used directly: ADAPT path name, or the function addpath() can be used in your own installation program.
This program was compiled and passed under Turbo C 2.0 and works normally on X86 compatible machines.
Attached is the source program ADAPT.C
1 #include
2 #include
3 #include
4 #define flag1 "set path="
5 #define flag2 "path="
6 #define endchar(s) (((char *)s))
7 main(int argc,char *argv)
8 { if(argc<2)
9 {printf("Usage: ADPATH newpath\n"
;exit(1);}10 addpath(argv);}
11 addpath(char *newpath)
12 {FILE *aut,*tmp;
13 char buffer;
14 char tname;
15 tmpnam(tname);
16 if((aut=fopen("c:\\autoexec.bat", "r"
)==NULL)17 {printf("erro open autoexec.bat"
;exit(1);}18 if((tmp=fopen(tname, "w"
)==NULL)19 {printf("error create tmpfile"
;exit(1);}20 while (!feof(aut))
21 {strcpy(buffer,""
;22 fgets(buffer, 256, aut);
23 if((strnicmp(buffer, flag1, strlen(flag1))==0) ||(strnicmp(buffer, flag2, strlen(flag2)))==0)
24 {if(endchar(buffer)=='\n'
endchar(buffer) ='\0';25 strcat(buffer, (endchar(buffer)==';' ? "" : ";"
);26 strcat(strcat(buffer, newpath), "\n"
;27 }fputs(buffer,tmp);
28 }fclose(aut);
29 fclose(tmp);
30 remove("c:\\autoexec.bat"
;31 rename(tname,"autoexec.new"
;32 system("copy autoexec.new c:\\autoexec.bat"
;33 remove("autoexec.new"
;34 }
□Shandong Xu Zhenhua
我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos

