Is there anyway you can run an executable C file immediately after windows gets restarted? For instance i have the following c code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
printf("Do you want to shutdown your computer now (y/n)\n");
scanf("%c", &ch);
if (ch == 'y' || ch == 'Y')
system("C:\\WINDOWS\\System32\\shutdown -s");
return 0;
}
and I want this code to get immediately executed when windows start
The simplest way to do what you're looking for is to put it in the registry under HKLM/Software/Microsoft/Windows/CurrentVersion/Run
. That will cause it to run every time Windows starts up. Just add a REG_SZ key (call it whatever you want) and set its value to the path to the executable for your program.
If you really want to create a Windows service (I don't think you do), then check out this link for an example of how to create one. That's overkill for what you want to do here, though - if all you want to do is run a program at startup, the registry key is the way to go.
Shutting down the system at startup seems like a weird thing to want to do...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.