下面这段代码是vc++对注册表的一系列操作,还有文件自身的复制功能
#include <stdio.h> #include <windows.h> int main(void) { char regname[]="Software\\Microsoft\\Windows\\CurrentVersion\\Run"; HKEY hkResult; int ret; //打开关键字
ret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult); ret=RegSetValueEx(hkResult,"door",0,REG_EXPAND_SZ,(unsigned char *)"%systemroot%\\door.exe",25); //设置键值
if(ret==0){ printf("success to write run key\n"); RegCloseKey(hkResult); } else{ printf("failed to open regedit.%d\n",ret); return 0; } char modlepath[256]; char syspath[256]; //取得程序名字
GetModuleFileName(0,modlepath,256); GetSystemDirectory(syspath,256); ret=CopyFile(modlepath,strcat(syspath,"\\door.exe"),1); if(ret) { printf("%s has been copyed to sys dir %s\n",modlepath,syspath); return 0; } }
开始的时候我建立工程类型成win32 application了,结果编译的时候老是出错“error LNK2001: unresolved external symbol _WinMain@16 ",通过百度得知,建立类型错了,应该建立成win32 console application的。