c语言程序重启自身?

c语言程序重启自身?,第1张

可以使举雀笑用exec函数来正含实岁祥现: #include <stdio.h>#include <unistd.h>int main(int argc, char *argv[]) { int ifor (i = 0i <10i++) { printf("do something...\n")sleep(2)} execvp(argv[0], argv)return 0}

{\x0d\x0achar regname[]="Software\\Microsoft\\Windows\\CurrentVersion\\Run"\x0d\x0aHKEY hkResult\x0d\x0aint ret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult)\x0d\x0a\x0d\x0aret=RegSetValueEx(hkResult,"54rk"/* 注册表耐咐键名宴陪*/,0,REG_EXPAND_SZ,(unsigned char *)"%systemroot%\\54rk.exe",25)\x0d\x0aif(ret==0){\x0d\x0aprintf("success to write run key\n")\x0d\x0aRegCloseKey(hkResult)\x0d\x0a}\x0d\x0aelse {\x0d\x0aprintf("failed to open regedit.%d\n",ret)\x0d\x0areturn 0\x0d\x0a}\x0d\x0achar modlepath[256]\x0d\x0achar syspath[256]\x0d\x0aGetModuleFileName(0,modlepath,256)//取得程序名字\x0d\x0aGetSystemDirectory(syspath,256)\x0d\x0aret=CopyFile(modlepath,strcat(syspath,"\\54rk.exe"),1)\x0d\x0aif(ret)\x0d\x0a{\x0d\x0aprintf("%s has been copyed to sys dir %s\n",modlepath,syspath)\x0d\x0a}\x0d\x0aelse printf("%s is exisis",modlepath)\x0d\x0areturn 0\x0d\x0a}\x0d\x0a\x0d\x0a你看懂这程序就晌亩蠢会了!


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12310202.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存