中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-18 11:16
47,814 topics / 349,907 posts / today 0 new / 48,259 members
DOS开发编程 & 发展交流 (开发室) » Repost: Add Path Program
Printable Version  2,344 / 2
Floor1 MYS Posted 2002-11-01 00:00
元老会员 Posts 1,637 Credits 5,170 From 广东佛山
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
Floor2 baobolz Posted 2002-11-03 00:00
中级用户 Posts 69 Credits 373
Nice
Floor3 禅宗 Posted 2002-11-03 00:00
元老会员 Posts 300 Credits 1,019 From 广东
This program is not as natural as directly using batch processing : )
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023