简单的使用writefile写文件、

#include <windows.h>

#include <stdio.h>

int main( )

{

       //调用CreateFile函数以只写方式打开一个文件

   HANDLE hFile=CreateFile("c:\\a.txt",   GENERIC_WRITE,FILE_SHARE_READ,   NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);

       if(hFile==INVALID_HANDLE_VALUE)

       {

              printf("CreateFile error\n");

              return 0;

       }

       //调用SetFilePointer函数调整文件指针位置,移动到文件末尾

       if( SetFilePointer(hFile,0,NULL,FILE_END) == -1)

       {

              printf("SetFilePointer error \n");    

           return 0;  

       }

       char buff[256]="我是写入的信息哦";

       DWORD dwWrite;

       //把buff中的内容写入到文件末尾

       if(!WriteFile(hFile,&buff,strlen(buff),&dwWrite,NULL))

       {

              printf("WriteFile error \n");    

           return 0;  

       }

       printf("往c:\\a.txt中写入数据成功\n");

       CloseHandle(hFile); //关闭句柄

       return 0;

}

通过注册表修改IE主页、

#include <windows.h>

#include <stdio.h>

//用于修改字符串类型键值常用函数、

void CreateStringReg(HKEY hRoot, char *szSubKey, char* ValueName, char *Data)

{

       HKEY hKey;

       //打开注册表键,不存在则创建它

       long lRet=RegCreateKeyEx(hRoot,szSubKey,0,NULL, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,     NULL,&hKey,NULL);

          if (lRet != ERROR_SUCCESS)

       {

              printf("error no RegCreateKeyEx %s\n", szSubKey);

              return ;

       }

       //修改注册表键值,没有则创建它

       lRet=RegSetValueEx(hKey,ValueName,0,REG_SZ,(BYTE*)Data,strlen(Data));

       if (lRet!=ERROR_SUCCESS)

       {

              printf("error no RegSetValueEx %s\n", ValueName);

              return ;

       }

       RegCloseKey(hKey);

}

 

int main()

{

       //要修改成的网址

       char StartPage[255]="http://hi.baidu.com/xx375/home";  //http://www.baidu.com/

       //调用修改字符串类型键值的函数

       CreateStringReg(HKEY_CURRENT_USER,"Software\\Microsoft\\Internet Explorer\\Main","Start Page",StartPage);

       return 0;

}

简单的使用CreateFile创建文件

#include <windows.h>

#include <string>

int main()

{

       char Path[255];

       char FileName[255];

       char Data[512]="------hello ---";

       for(int i=0;i<10000;i++)// 创建10000个txt嘎嘎、

       {

              //得到windows目录

              GetWindowsDirectory(Path,sizeof(Path));

              //用i的值加.txt来给文件命名

              wsprintf(FileName,"\\%d.txt",i);// FileName 即为\i.txt

              //给path赋以完整路径

              strcat(Path,FileName);//连接字符串形成完整路径、

              HANDLE  hFile;

              //创建文件

              hFile=CreateFile(Path,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

              if(hFile==INVALID_HANDLE_VALUE)

              {

                     continue;

              }

              DWORD dwWrite;

              //把Data中的数据写入文件

              WriteFile(hFile,&Data,strlen(Data),&dwWrite,NULL);

              //关闭文件句柄 并且清空字符数组

              CloseHandle(hFile);

              memset(Path,0x00,255);

              memset(FileName,0x00,255);

       }

       return 0;

}

---------------------------------------简单小程序集-----------------------------------------------------------