怎么用c语言实现开机自动运行程序

Python012

怎么用c语言实现开机自动运行程序,第1张

运行regedit 选择HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run然后在右边框中右击 新建->字符串值 然后右击新建的新值#1选择修改 在数值数据 输入程序路径 例如 你的程序若是在D盘Program Files下的名叫A的程序请输入D:\Program Files\a.exe这样就可以开机自动运行该程序了

在C语言中,程序重启自身可以通过调用exec或者system函数实现。下面是两种实现方法:

方法一:使用exec函数实现程序重启

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

int main()

{

printf("Program is running...\n")

// 休眠5秒钟

sleep(5)

printf("Program will restart now...\n")

// 使用exec函数重启程序

char *args[] = {"./program", NULL}

execvp(args[0], args)

return 0

}

方法二:使用system函数实现程序重启

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

int main()

{

printf("Program is running...\n")

// 休眠5秒钟

sleep(5)

printf("Program will restart now...\n")

// 使用system函数重启程序

system("./program")

return 0

}

需要注意的是,无论是使用exec函数还是system函数,都需要将程序的可执行文件名作为参数传入。另外,程序在重启之前需要先将需要保存的数据进行保存,否则数据会丢失。

你既然知道system()函数,就用windows的任务计划呀

也就是 at 命令。

按你说的意思即:system("at 12:00 net user")

若要每天12:00运行:system("at 12:00 at 12:00:00 /every:M,T,W,Th,F,S,Su net user")